Skip to content

Commit f25b9b1

Browse files
authored
Use 'self' if 'root' is undefined
I try to load libs with `import()`: ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script> function bootstrap() { // load all libraries then create & start application Promise.all([ import("./lib/http_vue_loader.js"), import("./lib/vue-router.js"), import("./lib/vue_esm_browser.js"), ]).then(([modLoader, modRouter, modVue, ...other]) => { debugger; }); } window.addEventListener("load", () => bootstrap()); </script> </head> <body> </body> </html> ``` but `root` is undefined in this case: ``` (function umd(root,factory){ if(typeof module==='object' && typeof exports === 'object' ) module.exports=factory() else if(typeof define==='function' && define.amd) define([],factory) else root.httpVueLoader=factory() })(this,function factory() {...}); ``` and I have an error "Cannot set property 'httpVueLoader' of undefined" at ``` root.httpVueLoader=factory() ``` `vue-router.js` uses [self](https://developer.mozilla.org/en-US/docs/Web/API/Window/self) in the same situation.
1 parent eef74fa commit f25b9b1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/httpVueLoader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
else if(typeof define==='function' && define.amd)
55
define([],factory)
66
else
7-
root.httpVueLoader=factory()
7+
(root = root || self, root.httpVueLoader=factory())
88
})(this,function factory() {
99
'use strict';
1010

0 commit comments

Comments
 (0)