$ .when和得分“这个”

时间:2014-06-18 16:17:33

标签: javascript backbone.js scope

我正在使用骨干并执行以下操作:

var self = this;
$.when(commentCollections.fetch()).done(function(comments){
  self.comments = comments;
  console.log(self.comments);
}).fail(function(){
  console.log('Could not fetch comments.');
});

console.log(this.comments);

正如你所看到的,我正在努力保留"这个"大头钉self.comments指的是"类级变量"设为[]

当我跑步时,我得到:

[]
Object {comments: Array[6]}

在控制台中。 []引用this.commentsObject ...引用self.comments有人可能会说,.done()内的所有内容都做得很好,但出于其他原因,我需要这就是我想要做的,概念是有效的。

为什么"这个"没被保存?

0 个答案:

没有答案