gpt4 book ai didi

javascript - 回调处理

转载 作者:太空宇宙 更新时间:2023-11-04 00:57:59 24 4
gpt4 key购买 nike

有人可以确认这两种方法是否实际上相同

process.nextTick(callback.bind(undefined, results));

对比。

process.nextTick(function() {
callback(results));
});

如果他们从 Node js 的 Angular 成功地使回调异步。

最佳答案

是的,它们可能是相同的。

不过有一个细微的差别:评估结果的时间。当您使用bind时,它会立即获取该值,当您使用回调时,该值在实际调用时确定。

它们不同的示例:

var results = 1;
process.nextTick(console.log.bind(console, results));
process.nextTick(function() { console.log(results)); });
results = 2;

// will log "1" and "2"

关于javascript - 回调处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28765671/

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