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); | |
}; |
@rtm if there's a spec, a library's behaviour can be:
1. conformant
2. non-conformant
3. undefined (by the spec)
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, but isn't "right" and "wrong" a little too "black" and "white"? It is certainly the case that all the major libraries seem to do it the way you call "right", but is the other way "wrong"?