On 4/25/16 1:35 PM, Adrian Sieber wrote:
Everytime I use `setTimeout()`, I wonder why the the arguments are in
the wrong order. Usually the callback functions comes last, but in
'setTimeout' it's exactly the other way round.
First, this is the wrong list: setTimeout is defined by
https://html.spec.whatwg.org/multipage/webappapis.html#dom-settimeout
not the ES language spec.
Second, note that the delay argument to setTimeout is optional.
So a polyfill would be something like:
```
newSetTimeout = (delay, callback, ...args) => {
if (typeof delay === 'function') {
setTimeout(delay, callback, ...args)
}
else {
setTimeout(callback, delay, ...args)
}
}
```
Third, this is not compatible, obviously. Consider what it would do with:
setTimeout("doSomething()", 1000);
You could check for function or string, but even that is not compatible
in cases like this:
setTimeout({ toString: () => "doSomething()" }, 1000);
and then you're left discussing whether such cases exist in practice and
whatnot, yes?
-Boris
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss