From f25b9b11a3ffee2f023314c42ea4aac4de090e34 Mon Sep 17 00:00:00 2001 From: Alex Gusev Date: Tue, 18 Aug 2020 18:48:33 +0300 Subject: [PATCH] Use 'self' if 'root' is undefined I try to load libs with `import()`: ``` ``` 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. --- src/httpVueLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/httpVueLoader.js b/src/httpVueLoader.js index 9bb2d9f..b9177e8 100644 --- a/src/httpVueLoader.js +++ b/src/httpVueLoader.js @@ -4,7 +4,7 @@ else if(typeof define==='function' && define.amd) define([],factory) else - root.httpVueLoader=factory() + (root = root || self, root.httpVueLoader=factory()) })(this,function factory() { 'use strict';