我正在创建插件并将默认值映射分配给我的对象。但是当我调用我的插件时,我得到的对象是未定义的。 这是我的代码
;(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)
但是我的配置对象未定义。我无法访问我的默认属性。我做错了什么?
由于
答案 0 :(得分:0)
$.extend({ dialog
dialog
未定义,应为$.dialog
。
使用console.log检查代码中的变量和对象,可以节省大量时间
答案 1 :(得分:0)
我这样更改了你的脚本并且有效
;(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)