日々プログラミング言語の勉強をしている京四郎のブログ -37ページ目

日々プログラミング言語の勉強をしている京四郎のブログ

日々プログラムの勉強をしている人がプログラム関係の記事を書くブログ

Javascript The Good Partsでsuperiorメソッドが載ってるが、この
superiorメソッドはjQueryと共に使用するときは、jQueryが正常
に動かないことがあるので注意が必要である。

jQueryだけでなく、Functionのprototypeをいじってる時点で
他のライブラリと共に使用するときに正常に動く保証はない。

Function.prototype.method = function (name, func) {
  this.prototype[name] = func;
  return this;
};

Object.method('superior', function (name) {
  var that = this,
  method = that[name];
  return function ( ) {
    return method.apply(that, arguments);
  };
});


参考
http://tcoztechwire.blogspot.jp/2012/01/if-using-jquery-careful-adding-methods.html