1

プロトタイプのいくつかのメソッドをオーバーライドして、次のElementようにカスタム フックを追加できるようにします。

Element.prototype._method = Element.prototype.method;
Element.prototype.method = function(){
  this._method.apply(this, arguments);
  // custom callback
}

ある時点で、元の方法を復元したいので、次のようにします。

Element.prototype.method = Element.prototype._method;

ただし、method要素がノードで呼び出されるとInvalid procedure call or argument、IE8 でエラーが発生するようです。元の方法を間違って復元していませんか?

4

1 に答える 1

0

deleteIE8 にはこの問題があり、解決するのは簡単ではないようですが、上書きされElement.prototypeたファイルの復元を試みることができます。

var old = Element.prototype.getElementsByTagName;
Element.prototype.getElementsByTagName = old;
// alert(document.body.getElementsByTagName('script').length); // this throws Error
delete Element.prototype.getElementsByTagName;
alert(document.body.getElementsByTagName('script').length); // Now it works as expected
于 2012-07-25T06:25:29.783 に答える