关于 __proto__和prototype的一些理解

var Person = function(name) {};

Person.prototype.say = function() {
console.log("Person say");
}

Person.prototype.age = 20;

var Man = function() {};
Man.prototype = new Person();
Man.prototype.physique = 'strong';

Man.prototype.age = 25;

var man = new Man();
man.say();
console.log(man.physique)
console.log(man.age);

//实例的__proto__ 指向的对象原型prototype
console.log(man.__proto__ === Man.prototype);
console.log(man.constructor === Person);
console.log(man.__proto__.constructor === man.constructor);

//对象的__proto__指向的都是Function的prototype
console.log(Person.constructor == Function);
console.log(Person.__proto__ == Function.prototype);
console.log(Person.__proto__.constructor == Function);
console.log(Person.prototype.constructor === Person);
console.log(Person.prototype.__proto__ === Object.prototype);

console.log(Function.constructor === Function);
console.log(Function.prototype.constructor === Function);
console.log(Function.__proto__.constructor === Function);
//Function.__proto__ 、 Object.__protot__ 和Function.prototype 指代就是同一个对象funtion
console.log(Function.prototype===Function.__proto__);
console.log(Function.prototype===Object.__proto__);

console.log(Object.prototype.__proto__=== null);
console.log(Object.__proto__.constructor == Function);

posted @ 2015-05-07 00:47  river-lee  阅读(204)  评论(0编辑  收藏  举报