您的位置:首页 > 其它

面向对象之prototype,__proto__

2016-06-02 16:16 218 查看
var person = function(name) {
this.name = name
};
person.prototype.getName = function() {
return this.name;
}

var zjh = new person('zhangjiahao');
zjh.getName(); //zhangjiahao
console.log("zjh.__proto__:");
console.log(zjh.__proto__);
console.log("person.prototype:");
console.log(person.prototype);

console.log("person.__proto__:");
console.log(person.__proto__);

console.log("Function.prototype:");
console.log(Function.prototype);
console.log("Function.__proto__:");
console.log(Function.__proto__);

console.log("Object.prototype:");
console.log(Object.prototype);
console.log("Object.__proto__:");
console.log(Object.__proto__);


  


Object.prototype.__proto__ = null; //这是终点

__proto__指向的是构建者的prototype,它构成连接了原型链。

函数对象的prototype是个对象,里面有构造函数等,可克隆其他对象的方法。

原型链参考文章:http://blog.csdn.net/chunqiuwei/article/details/22872325
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: