修正constructor的指向

function Aaa(){

}

//Aaa.prototype.constructor = Aaa;   //每一个函数都会有的,都是自动生成的
Aaa.prototype.name
= '小明'; Aaa.prototype.age = 20; Aaa.prototype = { 这是对象的引用,会修改constructor,要修正constructor的指向 constructor : Aaa, name : '小明', age : 20 }; var a1 = new Aaa(); alert( a1.constructor );
alert( a1.constructor==Object.prototype.constructor ); //true
 

 

你可能感兴趣的:(Constructor)