是否需要同时缓存'this'并在backbone.js中设置它的上下文

Is there a need for both caching 'this' and set its context in backbone.js?

本文关键字:js 设置 上下文 backbone 并在 缓存 this 是否      更新时间:2023-09-26

这段代码来自backbone.js,在视图的render方法中。我注意到作者都将"this"缓存到var"that",并将上下文设置为此。是否有理由缓存"this"并显式设置上下文?似乎只需要其中一个就可以了。

render: function () {
    var that = this;
    _.each(this.collection.models, function (item) {
        that.renderContact(item);
    }, this);
},

这应该像

一样简单
this.collection.each(this.renderContact, this);

将完成上面代码试图完成的任何结果