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
잠깐만. Class 객체가 인스턴스 객체를 확장하도록 만드는 방법이 있는지 묻는 중입니까? Editor.Advanced.prototype = {...}을 어떻게 설정하는지? –