文章博客

技术团队文档示例


第十天

<p>一些新特性</p> <pre><code class="language-javascript"> const cars = { '🚙BMW': '10', '🚘Tesla': '5', '🚖Lamborghini': '0' } Object.entries(cars).map(([name, count]) =&gt; { //padEnd appends ' -' until the name becomes 20 characters //padStart prepends '0' until the count becomes 3 characters. console.log(`${name.padEnd(20, ' -')} Count: ${count.padStart(3, '0')}`) }); 以下是打印的结果: "🚙BMW - - - - - - - Count: 010" "🚘Tesla - - - - - - Count: 005" "🚖Lamborghini - - - Count: 000"</code></pre> <pre><code class="language-javascript">async function doubleAndAdd(a, b) { a = await doubleAfter1Sec(a); b = await doubleAfter1Sec(b); return a + b; } doubleAndAdd('one', 2) .then(console.log) .catch(console.log); //NaN function doubleAfter1Sec(param) { return new Promise((resolve, reject) =&gt; { setTimeout(function() { let val = param * 2; isNaN(val) ? reject(NaN) : resolve(val); }, 1000); }); }</code></pre>

页面列表

ITEM_HTML