2012-07-25 96 views
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)); 
      ... 
     }); 
    }, 
}) 

如果数据是一个对象前。 JSON

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

是的,它是强调...;)

+0

你想在这里完成什么? – hvgotcodes 2012-07-25 17:58:55

+0

只是玩烬。无论如何,在创建对象之前测试道具。 – slothy 2012-07-25 18:12:32

回答

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

那么这个问题解决了吗? – 2012-07-25 18:15:31

+0

也许,是否会“扩展”原型? – slothy 2012-07-25 18:25:28

+0

如果这不是你的问题的解决方案,它不应该作为答案发布。您可以编辑您的原始问题以包含您想要的任何其他信息。如果这*是解决方案,那么请忽略。 – 2012-07-25 18:39:09