在创建Ember.Object时运行函数

时间:2014-12-30 22:11:20

标签: ember.js

我需要在创建特定对象时运行一个函数来验证环境设置是否正确。

这适用于Ember.Controller,但不适用于Ember.Object。

checkEnvironment : function() {

    ...

}.on('init'),

有没有办法以某种方式挂钩到构造函数?

1 个答案:

答案 0 :(得分:1)

函数实际上没有on方法,也许您会将它们与observers混淆?

fullNameChanged: function() {
   // deal with the change
}.observes('fullName').on('init')

您可以做的是覆盖init methid,并致电this._super()

  init: function() {
    this._super();
    this.checkEnvironment();
  },