View Code
1 function Person(){ 2 3 } 4 5 Person.prototype = { 6 name: "june"; 7 age: 24 8 };
上面代码中:
Person.prototype的constructor属性不再指向Person;
每创建一个函数,默认创建它的prototype对象,这个对象自动获得constructor属性;上述写法本质是重写了默认的prototype对象,因此constructor属性指向Object构造函数,不再指向Person函数。
View Code
var person = new Person(); alert(person instanceof Object) ; //true alert(person instanceof Person) ; //true alert(person.constructor == Object) ; //true alert(person.constructor == Person) ; //false