问题
This code: https://github.com/bjornharrtell/jsts/blob/master/index.js
refers to a variable named "GLOBAL".
When I run this in a browser, I get an error message:
"ReferenceError: GLOBAL is not defined"
Where does this GLOBAL come from, and why is it not defined?
回答1:
In Node.js, GLOBAL
is an alias to the global object (more commonly referred to as global
).
In browsers, it doesn't exist.
Browserify recognizes the global
alias, and will inject a reference to window
, but does not recognize GLOBAL
.
It was changed to global
four years ago
回答2:
Global variable came from the implementation of javascript in nodeJS
You can see it as Windows object for implementation of javascript in a web browser
回答3:
The code you are looking at is designed to run in a Node.JS environment.
The GLOBAL variable is documented in the node manual.
It is a feature provided by the Node environment and not a core part of JavaScript.
来源:https://stackoverflow.com/questions/22355887/what-is-the-global-variable-in-javascript