var Editor = {};
Editor.Basic = function(obj) {
this.config ={
value: obj
}
};
Editor.Basic.prototype = {
getValue: function() {
return this.config.value;
}
};
Editor.Advanced = function(obj) {
Editor.Basic.call(this, obj);
};
Editor.Advanced.prototype = {
config: {
notValue: !this.config.value
}
};
var extendByPrototype = function(obj1, obj2) {
for (var key in obj2.prototype) {
if (obj2.prototype.hasOwnProperty(key) && obj1.prototype[key] === undefined)
obj1.prototype[key] = obj2.prototype[key];
}
};
extendByPrototype(Editor.Advanced, Editor.Basic);
反正是有得到Editor.Advanced.prototype
扩展现有对象(递归的过程),而不是重写他们的? (如extendByPrototype
所示)原型继承和扩展现有的对象
我知道我会检查obj1.prototype[key] !== undefined
,但我不能确定什么,我需要做的,在一个通用的方式扩展现有的按键,而从Editor.Advanced.prototype
移动config
的构造和使用push
功能。
你想深入的扩展,jQuery有一个(平庸)算法 – Raynos 2012-03-14 17:50:32
坚持..小心检查我的理解了一下。你问是否有办法让一个Class对象扩展一个实例对象?就像你如何设置Editor.Advanced.prototype = {...}? – 2012-03-14 21:29:06