| 12345678910111213141516171819202122232425262728293031323334353637 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- function foo(){
- console.log("hello");
- }
- // console.log(foo.prototype);
- var arr = [1,2,3];
- // prototype 原型对象 任何对象下都会有原型 原型中有内置的方法 我们也可以向其中添加属性和方法
- // 数组的原型是Array.prototype
- // __proto__ 构造出的对象 指向的原型
- console.log(arr.__proto__);
- console.log(Array.prototype);
- console.log(Number.prototype);
- console.log(String.prototype);
- Array.prototype.loveCoding = function(){
- console.log("I love coding");
- console.log(this);
- }
- arr.loveCoding();
- Function.prototype.loveCoding = function(){
- console.log("I love coding");
- }
- foo.loveCoding();
-
- </script>
- </body>
- </html>
|