我正在使用骨干并执行以下操作:
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.comments
而Object ...
引用self.comments
有人可能会说,.done()
内的所有内容都做得很好,但出于其他原因,我需要这就是我想要做的,概念是有效的。
为什么"这个"没被保存?