Travis build: 1846

This commit is contained in:
30secondsofcode
2018-03-23 13:43:02 +00:00
parent 6d294a7f9d
commit 37137f9dde
2 changed files with 2 additions and 2 deletions

View File

@ -3904,7 +3904,7 @@ Use a `try... catch` block to return either the result of the function or an app
```js
const attempt = (fn, ...args) => {
try {
return fn(args);
return fn(...args);
} catch (e) {
return e instanceof Error ? e : new Error(e);
}

View File

@ -888,7 +888,7 @@ recorder<span class="token punctuation">.</span><span class="token function">sta
<span class="token function">tomorrow</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">);</span> <span class="token comment">// 2017-12-27T00:00:00 (if current date is 2017-12-26)</span>
</pre><button class="primary clipboard-copy">&#128203;&nbsp;Copy to clipboard</button></div></div><h2 style="text-align:center">Function</h2><div class="card fluid"><h3 id="attempt" class="section double-padded">attempt</h3><div class="section double-padded"><p>Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.</p><p>Use a <code>try... catch</code> block to return either the result of the function or an appropriate error.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">attempt</span> <span class="token operator">=</span> <span class="token punctuation">(</span>fn<span class="token punctuation">,</span> <span class="token operator">...</span>args<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">try</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token function">fn</span><span class="token punctuation">(</span>args<span class="token punctuation">);
<span class="token keyword">return</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token operator">...</span>args<span class="token punctuation">);
}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">e</span><span class="token punctuation">) {</span>
<span class="token keyword">return</span> e <span class="token keyword">instanceof</span> <span class="token class-name">Error</span> <span class="token operator">?</span> e <span class="token punctuation">:</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span>e<span class="token punctuation">);
}