gpt4 book ai didi

jquery - 我可以依赖已解析的 jquery 延迟对象的同步特性吗

转载 作者:行者123 更新时间:2023-12-01 00:18:56 25 4
gpt4 key购买 nike

Please Note: This question was about why the jQuery implementation of promises does not follow the Promises/A+ specification with regards to requirement 2.2.4.

<小时/>

我注意到一旦jQuery deferred object已解决,新来电done将同步调用任何doneCallbacks。

var d = $.Deferred();

d.resolve("Foo Bar!");

var fooBar = "Waiting";

d.done(function(data){fooBar = data; });

console.log(fooBar);//Will output "Foo Bar!" because the doneCallback is called synchronously

我原本期望将回调放在事件队列中(在这种情况下,控制台的输出将是“等待”),以便匹配在解析延迟对象之前调用完成的行为。我的期望不合理吗?

不过,我似乎找不到有关此行为的任何文档,因此我不确定这是否是我可以依赖的行为。

最佳答案

此行为已明确记录在此处:http://api.jquery.com/jquery.deferred/

Once the object has entered the resolved or rejected state, it stays in that state. Callbacks can still be added to the resolved or rejected Deferred — they will execute immediately.

关于jquery - 我可以依赖已解析的 jquery 延迟对象的同步特性吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14297398/

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