2011-09-17 4 views
1

이것은 사용자 정의 플러그인을 작성하는 jQuery 코드입니다.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'). tooltip ('init'); 'init'함수는 'get_me_now'변수를 어떻게 가져 옵니까?

답변

4
methods.get_me_now 

방금 ​​참조 할 수 있습니다.

+0

허, 죄송합니다. 내 실수 – genesis

관련 문제