函数调用apply

 1 var clicky = {
 2     wasClicked: function() {},
 3     addListeners: function() {
 4         var self = this;
 5         $('.clicky').click(function() {
 6             self.wasClicked();
 7         });
 8     }
 9 };
10 clicky.addListeners();
11 
12 
13 //使用apply
14 var proxy = function(func, thisObject) {
15         return (function() {
16             return func.apply(thisObject, arguments);
17         });
18     };
19 var clicky = {
20     wasClicked: function() {},
21     addListeners: function() {
22         var self = this;
23         $('.clicky').click(proxy(this.wasClicked, this));
24     }
25 };
posted @ 2012-07-23 15:42  小猩猩君  阅读(178)  评论(0编辑  收藏  举报