I have a set of named requirejs modules with constructor-as-a-function.
define('myModule', [ 'import1', 'import2' ], function(i1, i2) {
...
});
I want to be able to
Now, then I attaching a script with define
call to a document, script is successfully loaded, but module is not getting to be defined, constructor is not called.
Is it a normal behaviour? Is there some workaround to fix this?
script is successfully loaded, but constructor is not called. Is it a normal behaviour?
Yes. They are only executed when needed, the define
might be renamed as register
. Also it might need to wait for its dependencies anyway.
Is there some workaround to fix this?
If you want to execute it, just place a require()
call for it (not in the same file though).
I have some legacy code which knows nothing about modules and depends on file attachment instead.
While the script attachment does successfully load them (synchronously!), they will be executed asynchronously. You better would wrap the legacy code in require
s as well (which shouldn't break anything).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With