1
我想知道如何访问通过对象定义的子函数内的jQuery自定义函数。观察:通过子函数访问jQuery用户定义的函数内功能
(function($){
var methods = {
init : function (options) {
// getting the variable "data".
$.each (data, function(itemid, toll){
$.notification("update", data);
});
},
update : function (options) {
// ...
}
};
$.fn.notification = 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);
}
};
})(jQuery);
上述方法,使用$.notification ("update", data);
不起作用,因为该函数是在被限定的中间。那么,如何在不重复代码的情况下访问上述函数呢?即在method
变量之外写一个函数来更新,然后将该函数放入方法变量的update
索引中?先进的谢谢你。 :3