diff --git a/src/core/ob.js b/src/core/ob.js index 7c7d68ddf..4c617631f 100644 --- a/src/core/ob.js +++ b/src/core/ob.js @@ -29,24 +29,29 @@ * @abstract */ BI.OB = function (config) { - var props = this.props; - if (BI.isFunction(this.props)) { - props = this.props(config); - } - this.options = extend(this._defaultConfig(config), props, config); - this._init(); - this._initRef(); + this.__config = config; + this._constructor(); }; _.extend(BI.OB.prototype, { props: {}, init: null, destroyed: null, + _constructor: function () { + this._init(); + this._initRef(); + }, + _defaultConfig: function (config) { return {}; }, _init: function () { + var props = this.props; + if (BI.isFunction(this.props)) { + props = this.props(this.__config); + } + this.options = extend(this._defaultConfig(this.__config), props, this.__config); this._initListeners(); this.init && this.init(); }, diff --git a/src/core/shortcut.js b/src/core/shortcut.js index 53d6ae165..b40cac907 100644 --- a/src/core/shortcut.js +++ b/src/core/shortcut.js @@ -9,12 +9,14 @@ // 根据配置属性生成widget var createWidget = function (config) { - if (config["classType"]) { - return new (new Function("return " + config["classType"] + ";")())(config); - } - var cls = kv[config.type]; - return new cls(config); + + var widget = new cls(config); + + widget._init(); + widget._initRef(); + + return widget; }; BI.createWidget = function (item, options, context) { diff --git a/src/core/widget.js b/src/core/widget.js index f6add3ff0..eae1276e1 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -25,6 +25,9 @@ }); }, + // 覆盖父类的_constructor方法,widget不走ob的生命周期 + _constructor: function () {}, + beforeInit: null, // 生命周期函数