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
添加回答
举报
0/150
提交
取消