Created
May 19, 2013 15:38
-
-
Save icholy/5608026 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var callbacks = [1, 2, 3].map(function (x) { | |
| return function () { | |
| console.log(x); | |
| }; | |
| }); | |
| var wrong_invoke = function () { | |
| callbacks.forEach(function (callback) { | |
| setTimeout(callback, 0); | |
| }); | |
| }; | |
| var correct_invoke = function () { | |
| setTimeout(function () { | |
| callbacks.forEach(function (callback) { | |
| callback(); | |
| }); | |
| }, 0); | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rtm if there's a spec, a library's behaviour can be:
In this case, the spec does define the correct behaviour: executing the callbacks in the order they were registered.
This leaves only two options, so I would argue that this is a black and white situation.