2014-05-17 3 views
0

다음 코드가 있으며 _setProgress() 정의 된 오류 Uncaught TypeError: undefined is not a function (repeated 8 times)이 나타납니다.내 jQuery 플러그인에서 정의 된 메서드는 다음과 같은 오류를 반환합니다. undefined is not function?

내 플러그인 코드는 다음과 같다 :

;(
function($, window, document, undefined) 
{ 
    var pluginName   = "imageSlider2"; 
    var defaults   = { 
     onImagesLoaded : undefined, 
     onComplete  : undefined 
    }; 

    var max_image_height = null; 

    function Plugin(element, options) 
    { 
     this.element = element; 
     this.settings = $.extend({}, defaults, options); 
     this._defaults = defaults; 
     this._name  = pluginName; 

     this._init(); 
    } 

    Plugin.prototype = { 
     _init : function() 
     { 
      $(document).on(
       'images-loaded', 
       function(e) 
       { 
        //_hideProgress(); 
       } 
      ); 

      $(document).on(
       'slides-initiated', 
       function(e) 
       { 
        //_animationStart(); 
       } 
      ); 

      this._hideAny(); 
      this._addProgress(); 
     }, 
     _hideAny : function() 
     { 
      ... 
     }, 
     _randomID : function() 
     { 
      ... 
     }, 
     _addProgress : function() 
     { 
      ... 
      // This method just injecting an HTML element in my document 

      this._imagePreload() 
     }, 
     _setProgress : function(progress) 
     { 
      ... 
     }, 
     _imagePreload : function() 
     { 
      ... 

      $percent = 25; 
      this._setProgress($percent); 

      ... 
     } 
    }; 

    $.fn[pluginName] = function(options) 
    { 
     var plugin; 

     this.each(
      function() 
      { 
       plugin = $.data(this, "plugin_" + pluginName); 

       if(!plugin) 
       { 
        plugin = new Plugin(this, options); 

        $.data(this, "plugin_" + pluginName, plugin); 
       } 
      } 
     ); 

     return plugin; 
    }; 
} 
)(jQuery, window, document); 

답변

1

이 때문에 생성자 누락, 전체 프로토 타입을 무시하기 때문에 나는 매우 의심. 더 나은 다시

Plugin.prototype.constructor = Plugin; 
+0

이 내 문제를 해결할 또는 내 플러그인에 대한 더 나은 구조와 같은 생성자 설정

Plugin.prototype._init = function(){} 

또는

처럼 별도로 프로토 타입 방법을 할당하려고? –

관련 문제