我試圖在jQuery插件中使用.proxy()方法。不知道發生了什麼,但它不會調用methods.strobe。我已經得到了下面的示例代碼:使用.proxy調用插件方法()
(function($) {
var settings = {
}
var methods = {
init: function(options) {
alert('init fired');
$.proxy(methods.strobe,this);
return this;
},
destroy: function() {
},
strobe: function(){
alert('strobe fired');
},
show: function() {},
hide: function() {},
refresh: function() {}
};
$.fn.notify = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.notify');
}
};
})(jQuery);
$().notify();
我有這個的jsfiddle來進行測試:http://jsfiddle.net/CZqFW/
任何投入,將不勝感激。
真棒邁克,也許我應該仔細看看文檔中的例子!非常感謝:) – matt