Proposal: Switch position of delay and callback in signature of `setTimeout()`

Adrian Sieber mail at adriansieber.com
Mon Apr 25 17:35:50 UTC 2016


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.

So I propose that the order should be reversed to be consistent with other
functions.
Instead of `setTimeout(callback, delay[, arg][, ...])` it should be
 `setTimeout(delay, callback[, arg][, ...])`

By checking the type of the first two arguments (which one is the function)
backwards compatibility can be achieved.

So a polyfill would be something like:

```
newSetTimeout = (delay, callback, ...args) => {
  if (typeof delay === 'function') {
    setTimeout(delay, callback, ...args)
  }
  else {
    setTimeout(callback, delay, ...args)
  }
}
```

What do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160425/baa5feb9/attachment.html>


More information about the es-discuss mailing list