最近两天在看js原型,特地整理下,以后常看看
function Person() {}
Person.prototype.name = "zhangsan";
var p1 = new Person();
console.log( p1.constructor ); //function Person() {}
console.log( p1.constructor.prototype ); //{"name": "zhangsan"}
console.log( p1.__proto__ ); //{"name": "zhangsan"}
console.log('//----------------分割线-----------------------')
console.log( Person.constructor ); //function Function() {}
console.log( Person.__proto__ ); //function () {}
console.log( Person.prototype ); //{"name": "zhangsan"}
console.log( Person.prototype.constructor ); //function Person() {}
console.log( Person.prototype.constructor.prototype ); //{"name": "zhangsan"}
console.log( Person.prototype.__proto__ ); //Object.prototype
console.log('//----------------分割线--------------------')
console.log( Object.constructor ); //function Function() {}
console.log( Object.prototype ); //Object.prototype
console.log( Object.prototype.__proto__ ); //null,这个需要记忆下
console.log( Object.__proto__ ); //function () {}
console.log( Object.prototype.constructor ); //function Object() {}
console.log('//----------------分割线--------------------')
console.log( Function.constructor ); //function Function() {}
console.log( Function.prototype ); //function () {}
console.log( Function.__proto__ ); //function () {}
在这个
网址上看的,作者写的很细致用心,推荐对原型了解不是很深的同学看看,内容很多哦