Skip to content

Instantly share code, notes, and snippets.

@banyan
Created February 15, 2010 16:29
Show Gist options
  • Select an option

  • Save banyan/304770 to your computer and use it in GitHub Desktop.

Select an option

Save banyan/304770 to your computer and use it in GitHub Desktop.
664 // A global GUID counter for objects
665 guid: 1,
666
667 // 引数を3つ受け取れるが、引数が2個の場合しかの処理がない
668 proxy: function( fn, proxy, thisObject ) {
669 if ( arguments.length === 2 ) {
670 // $(".buttons").click($.proxy(obj, 'test')); の呼び方
671 if ( typeof proxy === "string" ) { // proxy が string なら
672 thisObject = fn; // thisObject は obj
673 fn = thisObject[ proxy ]; // obj["test"]
674 proxy = undefined; // 明示的に undefined を代入
675
676 // $("#test").click($.proxy(obj.test, obj));
677 } else if ( proxy && !jQuery.isFunction( proxy ) ) { // proxy があり、jQuery のメソッドではない
678 thisObject = proxy;
679 proxy = undefined;
680 }
681 }
682
683 if ( !proxy && fn ) {
684 proxy = function() {
685 // apply メソッドには、2つのパラメータを指定することができ、1つめは this にセットしたい値、 2つめは、パラメータの配列である。
686 return fn.apply( thisObject || this, arguments );
687 };
688 }
689
690 // Set the guid of unique handler to the same of original handler, so it can be removed
691 if ( fn ) {
692 proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
693 // 新しい $.proxy メソッドを呼ぶたびに増えていく
694 // ユニークであることを保証している
695 }
696
697 // So proxy can be declared as an argument
698 return proxy;
699 },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment