延长我的JavaScript对象,我有这样的代码:不能与原型
var Flippable = function(options, element) {
this.$el = $(element);
this._init(options);
};
Flippable.prototype = {
_init : function(options) {
this.options = $.extend(true, {}, $.Flips.defaults, options);
this.$pages = this.$el.children('div.f-page');
this.pagesCount = this.$pages.length;
this.History = window.History;
this.currentPage = this.options.current;
this._validateOpts();
this._getWinSize();
this._getState();
this._layout();
this._initTouchSwipe();
this._loadEvents();
this._goto();
},
foo: function(){alert("foo");}
}
但是当我打电话Flipppable.foo(),我得到了一个未定义。任何想法,我的语法关闭?
谢谢!
克里斯
** **更新
我的“M创建了以下这样一个插件:
$.fn.flippable = function(method) {
// Method calling logic
if (Flippable[method]) {
return Flippable[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return Flippable._init.apply(this, arguments);
遗漏的类型错误:无法调用未定义 '申请'}其他{ $ .error('Method'+ method +'在jQuery.flippable上不存在'); }
};
它borks在线:
return Flippable._init.apply(this, arguments);
_init是不确定的。
你用'new Flippable()'创建了一个对象吗? PS:通常修改'prototype',而不是完全覆盖。 – zerkms 2013-04-20 12:32:33