简体   繁体   English

浏览器中常见的内置javascript异步函数有哪些?

[英]What are some common built-in javascript asynchronous functions in browsers?

Functions like setTimeout , setInterval etc. which are part of the browser(and not of JS engine) are asynchronous in nature, what are some other built-in functions or methods that are asynchronous, which are either part of JS engine or of a browser?setTimeoutsetInterval等作为浏览器的一部分(而不是 JS 引擎)的函数本质上是异步的,还有一些其他的异步内置函数或方法,它们要么是 JS 引擎的一部分,要么是浏览器的一部分?

Also is it possible to implement something like setTimeout from with just javascript without using any browser APIs?是否可以在不使用任何浏览器 API 的情况下仅使用 javascript 实现类似setTimeout的功能?

 //setTimeout function without in-built function let sleep = (interval) => { const previousTime = Date.now() while(Date.now() - previousTime < interval){ //do nothing } } let mySetTimeout = (interval, func) => { sleep(interval) func() } let greet = () => { console.log("Hi") } mySetTimeout(5000, greet)

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

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