diff --git a/src/Action.js b/src/Action.js index f11f1ba..952378c 100644 --- a/src/Action.js +++ b/src/Action.js @@ -22,7 +22,6 @@ define( * @extends Observable */ function Action() { - Observable.apply(this, arguments); } /** diff --git a/src/Model.js b/src/Model.js index fd8be82..edf31f7 100644 --- a/src/Model.js +++ b/src/Model.js @@ -151,8 +151,6 @@ define( * @param {Object=} context 初始化的数据 */ function Model(context) { - Observable.apply(this, arguments); - this._store = {}; if (context) { diff --git a/src/Observable.js b/src/Observable.js index bb7fd13..6f4335f 100644 --- a/src/Observable.js +++ b/src/Observable.js @@ -26,6 +26,10 @@ define( * @public */ Observable.prototype.on = function(type, handler) { + if (!this._events) { + this._events = {}; + } + var pool = this._events[type]; if (!pool) { pool = this._events[type] = []; @@ -45,6 +49,10 @@ define( * @public */ Observable.prototype.un = function(type, handler) { + if (!this._events) { + return; + } + if (!handler) { this._events[type] = []; return; @@ -85,6 +93,10 @@ define( * @public */ Observable.prototype.fire = function(type, event) { + if (!this._events) { + return; + } + if (Object.prototype.toString.call(event) === '[object Object]') { event.type = type; } diff --git a/src/View.js b/src/View.js index 3986af3..5fcb9aa 100644 --- a/src/View.js +++ b/src/View.js @@ -21,7 +21,6 @@ define( * @extends Observable */ function View() { - Observable.apply(this, arguments); } /**