I wrote a AWS lambda function which buys €X worth of some currency on an exchange. For this I first have to find out the current price (getAskPrice), then calculate the amount to buy and post the order (buyLimitOrder). I've implemented both operations as promises,buyLimitOrdergets the...
然后我们有Function#bind。 function Test7(something) { this.something = something; setTimeout(function() { // `this` was bound to the parent's `this` using bind console.log(this.something); }.bind(this), 1000); }; new Test7('Num num'); 最近特别流行的ES2015箭头函数 function Test...
// 参考 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....
// Create a class for the elementclassWordCountextendsHTMLParagraphElement{constructor() {// Always call super first in constructorsuper();// count words in element's parent elementconstwcParent =this.parentNode;functioncountWords(node){consttext = node.innerText|| node.textContent;returntext.trim()...
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的核心部分。
See MDN - Iterables docs to find out more. @marocchino suggest just fine solution iterate over Array that was changed after map: function *upper (items) { yield* items.map(function (item) { try { return item.toUpperCase(); } catch (e) { return null; } }); } We can do it, ...
在空闲的时候加载些东西,可以看看 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()=>{ ...
// 例子,来自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...
Spec Right now you can't really tell if scrollIntoView scroll animation has finished nor you can't control the speed of the scroll and it might differ with each browser. So if you want to perform some action right after the animation has...