入れ子関数を呼び出して、パラメーターとして$(this)
渡すことなく使用することは可能$(this)
ですか?例:$(this).setValidators()
代わりにmethods.setValidators($(this))
(function($){
var methods = {
init: function(options){
var _this = this;
var inputs = $(":input)", _this);
inputs.each(function(){
methods.setValidators($(this));
//would it be possible to do the following somehow?
//$(this).setValidators();
});
},
setValidators: function(obj){
obj.on('click', anotherFunction);
},
/*
setValidators: function(){
$(this).on('click', anotherFunction);
}
*/
anotherFunction: function(){
//do stuff
}
}
$.fn.myPlugin = 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{
return(false);
}
};
})(jQuery);
$('form').myPlugin();