だから私はクラスを作成しました
function myClass()
{
}
メソッドで
myClass.prototype.theMethod=function()
{
}
どちらで問題ありませんが、可能であれば、このクラスを使用する必要がありますが、すべてを上書きするのではなく、メソッドにコマンドを追加する必要がありますか?
だから私はクラスを作成しました
function myClass()
{
}
メソッドで
myClass.prototype.theMethod=function()
{
}
どちらで問題ありませんが、可能であれば、このクラスを使用する必要がありますが、すべてを上書きするのではなく、メソッドにコマンドを追加する必要がありますか?
特定のオブジェクトでアクションをオーバーライドする必要がある場合は、次のことができます。
var myInstance = new myClass();
myInstance.theMethod = function () {
// do additional stuff
// now call parent method:
return myClass.prototype.theMethod.apply(this, arguments);
}
サブクラスの解決策はほとんど同じですが、インスタンスではなく、継承された「クラス」のプロトタイプで実行します。
このような:
var theOldMethod = myClass.prototype.theMethod;
myClass.prototype.theMethod=function()
{
//Do stuff here
var result = theOldMethod.apply(this, arguments);
//Or here
return result;
}