Javascript 如何在jQuery自定义插件中访问闭包的局部变量?
这是创建自定义插件的jQuery代码Javascript 如何在jQuery自定义插件中访问闭包的局部变量?,javascript,jquery,jquery-plugins,Javascript,Jquery,Jquery Plugins,这是创建自定义插件的jQuery代码 (function( $ ){ var methods = { get_me_now: 'abc', init : function( options ) { // how to access get_me_now in here? }, show : function( ) { // IS }, hide : function( ) { // GOOD }, update : function( conte
(function( $ ){
var methods = {
get_me_now: 'abc',
init : function( options ) { // how to access get_me_now in here? },
show : function( ) { // IS },
hide : function( ) { // GOOD },
update : function( content ) { // !!! }
};
$.fn.tooltip = function( method ) {
// Method calling logic
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 {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
我有一个变量“get_me_now”。我这样称呼它:$'test'。工具提示'init';
“init”函数如何获取“get_me_now”变量
methods.get_me_now
您可以直接引用方法
您可以直接引用方法