Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Use 'self' if 'root' is undefined #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flancer64
Copy link

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 in the same situation.

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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant