简体   繁体   English

回调是 Web API 绑定与 Javascript 引擎链接的唯一方式吗?

[英]Are callbacks the only way a web API binding is linked with the Javascript engine?

In the context of the browser, is it safe to say that the only possible link between a web API binding (eg: setTimeout() ) and the Javascript engine is via a callback function?在浏览器的上下文中,是否可以肯定地说 Web API 绑定(例如: setTimeout() )和 Javascript 引擎之间唯一可能的链接是通过回调函数?

ie: callback function -> callback queue -> event loop -> Javascript engine即:回调函数 -> 回调队列 -> 事件循环 -> Javascript 引擎

Or are there other mechanisms that could be used by some native code to communicate back with the Javascript engine?或者是否有其他机制可以被某些本机代码用于与 Javascript 引擎进行通信?

Are callbacks the only way a web API binding is linked with the JavaScript engine?回调是 Web API 绑定与 JavaScript 引擎链接的唯一方式吗?

No. document.createElement is one of many counter-examples.document.createElement是许多反例之一。

Are callbacks the only way an asynchronous web API binding is linked back to the Javascript engine?回调是异步 Web API 绑定链接回 Javascript 引擎的唯一方式吗?

Yes.是的。 Callbacks are the only way any asynchronous API works, that's pretty much the definition of "asynchronous API".回调是任何异步 API 工作的唯一方式,这几乎是“异步 API”的定义。 (Not just in JavaScript or on the web.) (不仅仅是在 JavaScript 或网络上。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM