Last active
December 16, 2015 19:09
-
-
Save roberttod/5482633 to your computer and use it in GitHub Desktop.
Change the context of require and then change back again
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
// Change require to new context | |
var newRequire = require.config({ | |
context: "new" | |
}); | |
// Define and then require module under context "new" | |
define("someModule", [], function () {return "newContext"; }); | |
newRequire(["someModule"], function (something) {console.log(something); }); | |
// Revert back to global context | |
require.config({ | |
context: "_" | |
}); | |
// Define and then require module under global context | |
define("someModule", [], function () {return "globalContext"; }); | |
require(["someModule"], function (something) {console.log(something); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment