我必须错过一些东西。 jQuery插件教程发现here,在“命名空间” - >“插件方法”部分,潜伏在下面的插件声明。我没有得到的是范围的方法变量;我的意思是,不应该将方法定义为工具提示中的变量?一旦这个匿名函数执行,如果我理解正确,方法超出了范围,因为它被定义为函数内的var。工具提示如何引用var方法,当调用tooltip时它将超出范围?我错过了什么?jQuery插件教程混乱
(function($){
var methods = {
init : function(options) { // THIS },
show : function() { // IS },
hide : function() { // GOOD },
update : function(content) { // !!! }
};
$.fn.tooltip = function(method) {
// Method calling logic
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.tooltip');
}
};
})(jQuery);
谢谢,不错的完整答案。 – gangelo