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

Oriol Bugzilla oriol-bugzilla at hotmail.com
Mon Apr 25 17:43:11 UTC 2016


`setTimeout` is not part of ECMAScript. You should suggest this to WHATWG instead.

- Oriol

From: mail at adriansieber.com
Date: Mon, 25 Apr 2016 17:35:50 +0000
Subject: Proposal: Switch position of delay and callback in signature of	`setTimeout()`
To: es-discuss at mozilla.org

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?

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160425/8fd88eb6/attachment.html>


More information about the es-discuss mailing list