What is the GLOBAL variable in Javascript?

不打扰是莪最后的温柔 提交于 2019-12-14 02:32:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!