gpt4 book ai didi

javascript - 是否需要缓存 'this' 并在 backbone.js 中设置其上下文?

转载 作者:行者123 更新时间:2023-12-03 17:46:20 25 4
gpt4 key购买 nike

此代码来自 backbone.js,在 View 的渲染方法中。我注意到作者将“this”缓存到 var“that”,并将上下文设置为 this。是否有任何理由既缓存“this”又显式设置上下文?它似乎只与其中一个一起工作。

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

最佳答案

这应该很简单

this.collection.each(this.renderContact, this);

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

关于javascript - 是否需要缓存 'this' 并在 backbone.js 中设置其上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24180408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com