是否可以在each
-function 中访问 jQuery 的插件对象?
var pluginName = 'pluginName',
Plugin = function(elem){
elem.add = function () {
console.log('foo');
return this;
};
};
$.fn[pluginName] = function () {
// this works
new Plugin(this);
return this;
// this doesn't!
// return this.each(function(){
// new Plugin($(this));
// });
};
var plugin = $('.foo').pluginName();
plugin.add();