时间:2021-07-01 10:21:17 帮助过:4人阅读
Object.prototype.m1 = function(){
alert("我是狮子");
}
function Class1(str){
this.p1 = str;
}
function Class2(){}
Class2.prototype.m1 = function(){
alert("你好");
}
var n1 = new Class1("毛狮子");
//@__proto__属性是对像父原型的引用
//@Object.prototype.__proto__=null
/*
n1的原型链
n1.__proto__=Class1.prototype
Class1.prototype.__proto__=Object.prototype
*/
var n2 = new Class2();
/*
n2的原型链
n2.__proto__=Class2.prototype
Class2.prototype.__proto__=Object.prototype
*/
n1.m1();//===Object.prototype.m1();
n2.m1();//===Class2.prototype.m1();
alert(n1.p1);//毛狮子
alert(n2.p1);//undefined