function aa(x){ this.x=x; this.sayx=function(){ console.log(x); } } aa.prototype = { do:function(){ console.log("嘟嘟") } } function bb(y,x){ this.y=y; aa.call(this,x); } //bb.prototype = Object.create(aa); bb.prototype = Object.create(aa.prototype); //bb.prototype = aa.prototype; //bb.prototype = new aa(); /*割了*/ //var f = funciton(){}; //f.prototype = aa.prototype;//或者new //bb.prototype = new f(); //bb.prototype = new aa("ccc"); bb.prototype.do1=function(){ console.log("嘟嘟1"); } bb.prototype.constructor=bb; var cc = new bb("aa","bb"); console.dir(cc);
总之一句话,原型链就是把一个对象链接到另外一个对象到另外一个对象....
对prototype赋值对象会破坏构造函数,prototype.dosthing这样能够避免掉。
prototype.proto函数