プロトタイプチェーンノート
6285 ワード
<script type="text/javascript">
1, object function
var obj = {};
var obj = new Object();
obj.constructor === Object
obj.__proto__ === Object.prototype __proto__ Object.prototype
2,
// constructor , 。
// constructor
// (constructor) 。 *
3,
// __proto__ , prototype
// , , Person.prototype = {name:'tom',age:18}
// , constructor( ) , ( ) prototype (Person)
: (Person.prototype) (Person) 。
4,__proto__
JS ( ) , __proto__ , 。
Person.prototype.constructor == Person;
person1.__proto__ == Person.prototype;
person1.constructor == Person;
5,
Javascript , :
var obj = {}
:
var obj = new Object()
obj (Object) 。 :
obj.constructor === Object
obj.__proto__ === Object.prototype
, Object, Array,Date,Function , String ,Boolean ,Number , 。 Array、 Date、Function,
6.
Object.prototype.__proto__ === null;
7.
// proto Function.prototype, (Empty function)
// <span style="color:#0000ff;"> Function.prototype, Object Function </span>
Number.__proto__ === Function.prototype // true
Number.constructor == Function //true
Boolean.__proto__ === Function.prototype // true
Boolean.constructor == Function //true
// Function.prototype, Object Function
Object.__proto__ === Function.prototype // true
Object.constructor == Function // true
// Function.prototype, Object Function
Function.__proto__ === Function.prototype // true
Function.constructor == Function //true
Array.__proto__ === Function.prototype // true
Array.constructor == Function //true
Date.__proto__ === Function.prototype // true
Date.constructor == Function //true
//
function Person() {}
//
var Perosn = function() {}
console.log(Person.__proto__ === Function.prototype) // true
** Function.prototype, Object Function 。 ·Function.prototype· 。 length、call、apply、bind **
// Function.prototype typeof XXX.prototype function prototype。 prototype
console.log(typeof Function.prototype) // function
console.log(typeof Object.prototype) // object
console.log(typeof Number.prototype) // object
console.log(typeof Boolean.prototype) // object
console.log(typeof String.prototype) // object
console.log(typeof Array.prototype) // object
console.log(typeof RegExp.prototype) // object
console.log(typeof Error.prototype) // object
console.log(typeof Date.prototype) // object
console.log(typeof Object.prototype) // object
( ) __proto__ Function.prototype, Function.prototype __proto__ ?
JavaScript , ? console.log(Function.prototype.__proto__ === Object.prototype) // true、
JS , / 。 Object.prototype :toString、valueOf、hasOwnProperty
Object.prototype proto ? Object.prototype.__proto__ === null , null。( , , ?)
8,prototype
proto Function.prototype, (Empty function)
Object.getOwnPropertyNames(Function.prototype)
9,
: __proto__ Function.prototype, (Empty function)
: __proto__ prototype
10, ( )
function Person(){}
var person1 = new Person();
console.log(person1.__proto__ === Person.prototype); // true
console.log(Person.prototype.__proto__ === Object.prototype) //true
console.log(Object.prototype.__proto__) //null
Person.__proto__ == Function.prototype; //true
console.log(Function.prototype)// function(){} ( )
var num = new Array()
console.log(num.__proto__ == Array.prototype) // true
console.log( Array.prototype.__proto__ == Object.prototype) // true
console.log(Array.prototype) // [] ( )
console.log(Object.prototype.__proto__) //null
console.log(Array.__proto__ == Function.prototype)// true
:
1,Object.__proto__ === Function.prototype // true
Object , new Function() , Object.__proto__ Function.prototype。( :「 __proto__ Function.prototype」)
2,Function.__proto__ === Function.prototype // true Function , new Function() , Function.__proto__ Function.prototype。
3, Function.prototype.__proto__ === Object.prototype //true
, 。
Function.prototype , __proto__ Function.prototype, , , 。
JS , , , Object.prototype。Object.prototype.__proto__ === null, 。
11,
JS 。
__proto__ prototype
var animal = function(){};
var dog = function(){};
animal.price = 2000;
dog.prototype = animal;
var tidy = new dog();
console.log(dog.price) //undefined
console.log(tidy.price) // 2000
var dog = function(){};
dog.prototype.price = 2000;
var tidy = new dog();
console.log(tidy.price); // 2000
console.log(dog.price); //undefined
var dog = function(){};
var tidy = new dog();
tidy.price = 2000;
console.log(dog.price); //undefined
(tidy) (dog.prototype) 。 , , (tidy) (dog.prototype) ,
(tidy) (dog) 。
:
1, , , , ,js , , __proto__(Object.prototype) ,
Object.prototype._proto_( null), , undefined
2, , , , , 。
:
</script>
</code></pre>
</div>
<p> </p>
</div>
<p> :https://www.cnblogs.com/jeff-zhu/p/11423389.html</p>
</div>
</div>
</div>
</div>