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函數