function Person(name,age){
this.name=name;
this.age=age;
this.getName=function(){
console.log(this.name);
}
}
Person.prototype.sayAge="hehe";
var p = new Person("lucy","21");
console.log(1,p instanceof Person);
console.log(2,p.constructor === Person);
console.log(3,p.hasOwnProperty('getAge'),p.sayAge);
Person.prototype={
getAge:function(){
alert(this.age);
}
}
var d = new Person("lucy","21");
console.log(1,d instanceof Person);
console.log(2,d.constructor === Person);
console.log(3,d.hasOwnProperty('getAge'),d.sayAge);
如上,不知哪位能给出图形描述此题中原型链指向的情况~~~
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
凑合着看吧,图里还有 Person.prototype的指向没画出来
具体图其实可以参考《javascript高级程序》 面向对象的程序设计章节。
//修订1.
对象p,d都并不包含constructor属性