皆さん、この質問について私を助けてくれませんか。
var Module = function ( options ) {
var settings = {
selector: 'body',
declaration: function () {
return{
init: function () {
console.log( 'nodule initialize' );
},
destroy: function () {
console.log( ' module destroyed' );
}
}
}
};
this.declaration = options.declaration || settings.declaration;
this.selector = options.selector || settings.selector;
};
var Registration = function ( options ) {
this.selector = options.selector || **strong text**;
this.declaration = options.declaration
}
app.utils.extend( Module, Registration );
var m_registration = new Registration( {
declaration: function ( f ) {
return {
init: function () {
},
destroy: function () {
}
}
}
} );
私の主な質問は、登録 のインスタンスを作成するときに渡される数量引数が必要ない場合、m_registration でModule.selectorプロパティを継承する方法です。
関数 app.utils.extend() の私の実現:
var app.utils.extend = function ( from, to ) {
var F = function () {
};
F.prototype = from.prototype;
to.prototype = new F();
to.prototype.constructor = to;
to.superclass = from.prototype;
}
更新:
これらの方法を使用している場合:
var Registration = function ( options ) {
Module.call(this, { selector : options.selector });
this.declaration = options.declaration
}
このクラスがどのインスタンスから拡張されたか、または継承が本当にわからない場合に、継承をどのように使用できるか。