简体   繁体   English

试验在余烬对象中的属性

[英]test for a property in ember object

Let's say: 比方说:

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));
            ...
        });
    },
})

Where data is an Object ex. 其中数据是对象ex。 JSON JSON格式

Is there any Ember way of testing or just a JS OO way?? 是否有任何Ember测试方法或只是JS OO方法?

Yes it is underscore... ;) 是的,它是下划线...;)

Ok, context error, my apologies...poor me. 好吧,上下文错误,我的道歉...可怜的我。

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);
   },
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM