我正在使用显示原型模式开发一个 jQuery 插件,我在实例化我的对象时遇到了一些麻烦。下面,插件的代码:
(function($) {
var GammadiaCalendar = function(elem, options) {
this.elem = elem;
this.$elem = $(elem);
this.options = options;
};
GammadiaCalendar.prototype = function() {
var defaults = {
message: 'Hello world!'
},
init = function() {
this.config = $.extend({}, this.defaults, this.options);
this.displayMessage();
return this;
},
displayMessage = function() {
alert(this.config.message);
};
return {
displayMessage : displayMessage
};
};
GammadiaCalendar.defaults = GammadiaCalendar.prototype.defaults;
$.fn.GammadiaCalendar = function(options) {
return this.each(function() {
new GammadiaCalendar(this, options).init();
});
};
})(jQuery)
我在实例化时得到GammadiaCalendar 未定义:
var gc = new GammadiaCalendar('id');