0

比方说:

Foo.user = Ember.Object.extend({
    username:null,
    name:null,
    loadData:function(data){
        _.each(data, function(value, key){
            console.log(this.hasOwnProperty(String(key)), key, String(key));
            console.log((String(key) in this));
            console.log(key in this.__proto__);
            console.log(_.has(this, key));
            ...
        });
    },
})

其中数据是一个对象 ex。JSON

是否有任何 Ember 测试方式或只是 JS OO 方式?

是的,它是下划线... ;)

4

1 回答 1

0

好的,上下文错误,我很抱歉……可怜的我。

Foo.user = Ember.Object.extend({
  username:null,
  name:null,
  loadData:function(data){
      _.each(data, function(value, key){
          console.log(this.hasOwnProperty(String(key)), key, String(key));
          console.log((String(key) in this));
          console.log(key in this.__proto__);
          console.log(_.has(this, key));
          ...
      }, this);
   },
})
于 2012-07-25T18:11:17.967 回答