考慮下面的代碼(jQuery的模式,我想):繼承的jQuery狀的圖案
function child(){
return new child.methods.init();
}
child.methods = child.prototype = {
init: function(){
return this;
},
test: function(){
console.log('test');
return this;
}
}
//this code doesn't work
child.methods.prototype = {
test1: function(){
console.log('test1');
return this;
}
}
child.methods.init.prototype = child.methods;
//Using child chaining api. test() will work, but test1() will not.
child().test().test1();
我需要繼承其他子對象(文字對象給出了簡化)。 如何從對象繼承子函數模式?
您正在尋找'child.methods.test1 = function(){...}'。哦,請不要使用jQuery模式,因爲它太混亂了。 – Bergi