function Person(name,age){
this.name = name;
this.age = age;
}
Person.prototype.getAge = function(){
return this.age;
}
Person.prototype.getName = function(){
return this.name;
}
var p = new Person("Nicholas",18);
console.log(p.constructor === Person.prototype.constructor)// true
因为 p.constructor回去找p.__proto__中的值,而 p.__proto__ 由 Person.prototype而来,所以相等
改
function Person(name,age){
this.name = name;
this.age = age;
}
Person.prototype = 1
var p = new Person("Nicholas",18);
console.log(p.constructor); //ƒ Object() { [native code] }
为什么不是 Person.prototype.constructor的Number,而是object
而且 p.constructor === Person.prototype.constructor也返回false
鸿蒙传说
相关分类