Answer the question
In order to leave comments, you need to log in
Requirejs: how to call a module immediately?
I am writing an embedded application, something like a huge jQuery plugin. The "master" module must request another module, which in turn loads other modules. It (the main module) should create a global function. The problem is that this function is created with a delay due to the fact that the modules are asynchronous.
main.js:
define( 'main', [ 'blah' ], function( Blah ) {
window.Blah = Blah;
});
require( ['main'] );
new Blah(); // Blah is not defined
<script src="blah-built.js"></script>
<script>new Blah(); // Blah is not defined </script>
( function() {
window.Blah = function() {
var _this = this;
require([ 'blah' ], function( _Blah ) {
_this.me = new _Blah();
});
};
})();
Answer the question
In order to leave comments, you need to log in
window.Blah = Blah;
You just broke the whole concept of requirejs.
Gotta change something
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question