Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery自定义插件中访问闭包的局部变量?_Javascript_Jquery_Jquery Plugins - Fatal编程技术网

Javascript 如何在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

这是创建自定义插件的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( 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
您可以直接引用方法

您可以直接引用方法