事件代理 proxy
1 var proxy = function(func, thisObject) { 2 return (function() { 3 return func.apply(thisObject, arguments); 4 }); 5 }; 6 7 //example 8 var clicky = { 9 wasClicked: function() {}, 10 addListeners: function() { 11 var self = this; 12 $('.clicky').click(proxy(this.wasClicked, this)); 13 } 14 };
JQ也有这个方法