官方描述: 函數(shù)對象被創(chuàng)建時(shí),Function構(gòu)造器產(chǎn)生的函數(shù)對象會(huì)運(yùn)行這樣一些代碼:
this.prototype = {constructor: this};
1.prototype
是函數(shù)對象的屬性,普通對象沒有該屬性:
普通對象沒有prototype屬性.png
函數(shù)對象prototype.png
2.函數(shù)對象和普通對象都有__proto__
屬性,它指向該對象原型的prototype
構(gòu)造函數(shù)俐芯、實(shí)例與原型關(guān)系圖
構(gòu)造函數(shù)、實(shí)例與原型關(guān)系圖.png
function Person() {}
let person = new Person();
// 在所有實(shí)現(xiàn)中都無法訪問,以下的訪問方式已被棄用。
console.log(Person.__proto__ === Function.prototype);
console.log(person.__proto__ === Person.prototype);
// 判斷__proto__的指向
console.log(Object.prototype.isPrototypeOf(person));
console.log(Object.getPrototypeOf(person) === Func.prototype); // 推介
// 判斷Func原型的constructor指向
console.log(Person.prototype.constructor === Person)
// Person和person中的constructor屬性指向它的構(gòu)造函數(shù)
console.log(person.constructor === Person);
console.log(Person.constructor === Function);