こんにちは、私はノードが初めてで、MVC アプリを構築しようとしています。コントローラーとモデルについては、utils.inherits を使用して基本クラスとサブクラスを作成できました。ビューについては、base、html/json、module の 3 つのレベルを作成したいと思います。各レベルには、インスタンスの作成時に呼び出す必要があるコンストラクトと呼ばれる関数があり、最上位でそれを呼び出すと、各レベルに連鎖する必要があります。
ベース ビュー:
function Base_view( ) {
this._response = null;
};
Base_view.prototype.construct = function( res ) {
this._response = res;
};
HTML ビュー:
var util = require( 'util' ),
Base_view = require( './view' );
function Html_view( ) {
Base_view.apply( this, arguments );
}
util.inherits( Html_view, Base_view );
Html_view.prototype.construct = function( res, name ) {
this.constructor.super_.prototype.construct.apply( this, arguments );
};
モジュール ビュー:
var util = require( 'util' ),
Html_view = require( './../base/html' );
function Main_view( ) {
Html_view.apply( this, arguments );
}
util.inherits( Main_view, Html_view );
Main_view.prototype.construct = function( ) {
this.constructor.super_.prototype.construct.apply( this, arguments );
};
モジュール ビューの次の行は、未定義のエラーを生成します。
this.constructor.super_.prototype.construct.apply( this, arguments );
一度だけサブクラス化すると、親クラスのコンストラクト メソッドが正しく呼び出されます。複数回延長するにはどうすればよいですか?
この投稿では: util.inherits - 代替または回避策変更された utils.inherits メソッドがありますが、それを行うように見えますが、使用方法がわかりませんか? モジュールで両方のクラスを要求し、3つすべてをパラメーターとして配置しようとしました。
ありがとう!