简体   繁体   中英

Callback meaning in MDN

我对MDN上的回调的含义有疑问,例如array.filter ,如何识别在其中使用的回调是同步还是异步?

You need to figure out the meaning using the following approach: it will be asynchronous if the API itself does asynchronous operations. For example AJAX, Web Sockets, WebRTC, Web Workers are asynchronous APIs.

All other Web browser APIs like Array.prototype functions are all synchronous.

That is, callback doesn't mean asynchronous or synchronous, but just you need to give a function as argument with some input parameters or just a parameterless function .

It would be great if asynchronous functions would be suffixed with Async . For example, setTimeoutAsync(...) , or sendAsync , but this just a subjective (but very effective) coding convention not used in JavaScript (it's sad...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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