我有一些本地函数放在插件的方法中,我想知道我是否可以从外部访问插件的方法函数?
这是我的代码,
$(document).ready(function(){
$.fn.hilight.init.plugins();
});
(function ($) {
var pluginName = 'hilight';
var methods = {
init: function(options){
var base = this;
// Method's function.
base.plugins = function() {
alert("an internal function");
}
var o = $.extend(true, {}, $.fn.hilight.defaults, options );
}
}
$.fn[pluginName] = 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 ); // always change 'init' to something else if you different method name.
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.plugin' );
}
return this;
};
$.fn[pluginName].defaults = {
foreground: "red",
background: "yellow"
}
}( jQuery ));
但我当然得到错误,
TypeError:$ .fn.hilight.init未定义[打破此错误]
$ fn.hilight.init.plugins();
我是如何实现这一目标的?