简体   繁体   中英

How to create a global variable in javascript (using webpack)

I'm using React JS with webpack, webpack-dev-server and Ecmascript 6. I have an undeclared variable in the file named data.js. However, I cannot modify the data.js file since its standard. So is there a way by which I can make the variable global from another js file? I tried declaring window.myvarname in another file where data.js is referenced using import statement but its still giving an error Uncaught ReferenceError: myvarname is not defined

define object in some file like below

var data={

  myvarname:""

};

and call where you want like this

data.myvarname;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM