2012-02-29 14 views
0

私はプラグインを作成していて、オブジェクトにデフォルトマップを割り当てています。しかし、私は私のプラグインを呼び出すと、私はオブジェクトが未定義になります。 は、ここに私のコードプラグインがオブジェクトを作成していません。オブジェクト状態の表示が定義されていません

;(function($){ 

    $.dialog = { 

     defaults : { 

      timeout: 0 , 
      showClose: true, 
      message: "Your message", 
      .... 

     } //end of defaults 

    }; //end of $.dialog = {} 

    $.extend({ 

     dialog : function(userConfig) { 

      var config = (userConfig) ? $.extend({}, $.dialog.defaults, userConfig) 
             : $.dialog.defaults; 
      $.dialog.createUI(config); 

      return this; 

     } //end of function(userConfig) 

    }); //end of $.fn.extend({}) 

    $.dialog.createUI = function(config){ 
     ..... 
    } 

})(jQuery); //end of (function($){} 

であり、私はこの

$(document).ready(function(){ 

    $.dialog(); 

}); //end of $(document).ready(fn) 

のようにそれを呼び出すことですが、私は、私のconfigオブジェクトは未定義取得しています。私はデフォルトのプロパティにアクセスできません。何が間違っているのですか? $.dialogでなければなりません

おかげ

答えて

0

を大幅に節約します私はこのようなスクリプトを変更し、それはありません@charlietfl

;(function($){ 
    $.extend({ 
     dialog : function(userConfig) { 
      var config = (userConfig) ? $.extend({}, $.dialog.defaults, userConfig) : $.dialog.defaults; 
      $.dialog.createUI(config); 
      return this; 
     } //end of function(userConfig) 
    }); //end of $.fn.extend({}) 

    $.dialog.defaults = { 
     timeout: 0, 
     showClose: true, 
     message: "Your message" 
    }; 

    $.dialog.createUI = function(config){ 

    } 
})(jQuery); //end of (function($){} 

$(document).ready(function(){ 
    $.dialog(); 
}); //end of $(document).ready(fn) 
+0

を働いていた、あなたの提案は動作しませんでしたありがとう。しかし、私のスクリプトで何が間違っています。何を私は間違っていたのですか? – Basit

+0

'$ .dialog = {defaults:{'の代わりに '$ .dialog.defaults'を使用しました。それはあなたのために働いていますか? – arunes

+0

はい、私はあなたの答えを記した理由です:)。しかし '$ .dialog.defaults = {}'は '$ .dialog = {defaults:{'と同じです。私の場合は、まずオブジェクトを作成してプロパティを割り当てます。あなたの場合は、同じ行にプロパティを作成して割り当てます。どちらの場合も** $。dialog **には不公平なデフォルトがあります。違いは何ですか? – Basit

0
$.extend({ dialog 

dialogは、未定義です。あなたのコード内の変数やオブジェクトをチェックする 使用にconsole.log、あなたの時間

関連する問題