functiongetMoneyBack(money){returnnewPromise((resolve,reject)=>{if(typeofmoney!=='number'){reject(newError('money is not a number'))}else{resolve(money)}})}getMoneyBack(1200).then((money)=>{console.log(money)}) Promise 对象 它们是JS中构成Promise的核心部分。 所以,我们为什么需要JS中的Pro...
// 参考 MDN Background Tasks API 这篇文章// https://developer.mozilla.org/zh-CN/docs/Web/API/Background_Tasks_API#examplelet taskHandle = null;let taskList = [() => {console.log('task1')},() => {console.log('task2')},() => {console.log('task3')}]function runTaskQueue(dea...
http.get('https://api.github.com/users', function(users) { /* Display all users */ console.log(users); http.get('https://api.github.com/repos/javascript/contributors?q=contributions&order=desc', function(contributors) { /* Display all top contributors */ console.log(contributors); http....
// 例子,来自MDNvarstart =null;varelement =document.getElementById('SomeElementYouWantToAnimate'); element.style.position='absolute';functionstep(timestamp) {if(!start) start = timestamp;varprogress = timestamp - start; element.style.left=Math.min(progress /10,200) +'px';if(progress <2000...
在空闲的时候加载些东西,可以看看 qiankun 的例子,用来预加载 js 和 css functionprefetch(entry:Entry,opts?:ImportEntryOpts):void{ if(!navigator.onLine||isSlowNetwork) { // Don't prefetch if in a slow network or offline return; } requestIdleCallback(async()=>{ ...
This property in Node.js is crucial, as it gives control back to the event loop as soon as an asynchronous request is sent, thus allowing a new event from the queue to be processed.Figure 3.1 shows how this works:Figure 3.1: Control flow of an asynchronous function's invocation...
// 例子,来自MDNvarstart =null;varelement =document.getElementById('SomeElementYouWantToAnimate'); element.style.position='absolute';functionstep(timestamp) {if(!start) start = timestamp;varprogress = timestamp - start; element.style.left=Math.min(progress /10,200) +'px';if(progress <2000...