Ensure global setTimeout reference is captured in require.js#1402
Ensure global setTimeout reference is captured in require.js#1402platinumazure wants to merge 4 commits into
Conversation
…t clobbering setTimeout does not break everything.
|
I generally prefer to avoid using the "global" object, or whatever "this" is set to when requirejs evaluates, as it can be a flexible thing, assumes too much about the environment, where relying on scope feels more composable to me. In "use strict" code "this" can be undefined too. The "global" use in requirejs right now is only around shim support which is a secondary, bridging feature, not something core to the loader, so I am OK if the user wants "use strict" code to be true for them to use the loader without shim exports support. So I am not too eager to do this change. I also want to be sure the issue is not something else, as sinon and requirejs have both been in use for a while. Going to close for now, but feel free to continue discussion here and we can reopen later if needed. |
|
There is some precedent in using a "global" variable and accessing setTimeout from there, which works even in Node.js and other environments. See [qunit.js][1](line 21 is where setTimeout is captured, and about 2/3 of the way down is where the closure is invoked with a global object). Can you enumerate a specific example of where |
Ensuring global setTimeout reference is captured in require.js so that clobbering
setTimeoutdoes not break everything.This is useful/necessary when using RequireJS with a unit test framework that simulates
setTimeout(for example sinon.js). Since RequireJS relies on the default behavior of setTimeout and is a library which ideally should function the same way even when other frameworks are involved, it seems worthwhile to close over the defaultsetTimeoutfunction.I've also added a unit test file to capture this-- please let me know if that can be improved.