我是新来的,所以忍受我,
我有以下类型的插件模式
;(function ( $, window, document, undefined ) {
'use strict';
defaults = {..}
// The actual plugin constructor
function Plugin ( element, options ) {
this.init();
}
Plugin.prototype = {
init: function () {
....
},
privateFunc: function ( options) {
//do private stuff
}
};
$.fn.plugin = function (method, options ) {
if (method === undefined){
method = 'null';
}
switch(method){
case 'null':
return this.each(function() {
if ( !$.data( this, "plugin_custom" ) ) {
$.data( this, "plugin_custom", new Plugin( this, options ) );
}
});
case 'publicFunc':
// do stuff with options and then call privateFunc with some data
break;
}
};
})( jQuery, window, document );
我想从privateFunc
致电publicFunc
,但我不确定如何访问它
答案 0 :(得分:2)
Plugin.prototype.privateFunc
实际上并不是私人的;作为原型的一部分意味着公众可见度;这意味着您可以像这样访问它:
var plugin = $.data( this, "plugin_custom");
plugin.privateFunc();