我想知道是否有一种方法可以为 jQuery 插件定义变量并使其可以从外部查看。(用于调试目的)
我希望这个插件可能在多个 DOM 元素上被调用,所以我的想法是每次调用都会维护自己的一组变量。
我希望像这样检查 Firebug 中的变量值:
$('#hp-feat-promo').featuredPromo.moduleValues.totalNumSlides
但这不起作用。任何想法这将如何工作,或者我的理解是错误的?
(function($){
$.fn.featuredPromo = function (options) {
/* Inside a jQuery plugin this refers to the jQuery object
* Inside of the nested function declarations, this refers to the local object, so if
* you still want to refer to the original DOM object, you need to hhave a pointer to the top-level this
*/
var self = this;
/* Create some defaults, extending them with any options that were provided */
var defaults = {
targetElement: self.find('.window ul li'),
isAuto: true
},
settings = '';
/* settings is all the configurable parameters, defaults + options (overrides) */
settings = $.extend(defaults, options);
this.moduleValues = {
totalNumSlides: settings.targetElement.length,
autoRotate: settings.isAuto,
currentSlide: 0,
nextSlide: function() {
},
prevSlide: function() {
}
};
return this.each(function() {
});
};
jQuery(function(){
$('#hp-feat-promo').featuredPromo();
});
})(jQuery);