'spidermonkey global object image
I've been reading spidermonkey doc (SpiderMonkey - JSAPI User Guide) and feel kind hard to understand how the relationship betbetween global object and all the variable and functions.
Say I have the code below in test.js:
var Global_Var1 = 1;
var Global_Var2 = 2;
var Global_Func1 = function() {};
var Global_Func2 = function() {};
var Namespace_N1 = Namespace_N1 || {};
var Namespace_N2 = Namespace_N2 || {};
Namespace_N1.functionN1 = function() {};
Namespace_N2.functionN1 = function() {};
and what will be inside the spidermonkey's "global object" at runtime? will it be something like (a tree view):
Global Object (JS::RootedObject, JSClass)
- Global_Var1 (as object property ? with value 1)
- Global_Var2 (as object property ? with value 2)
- Global_Func1 (as object property ? whose value is function)
- Global_Func2 (as object property ? whose value is function)
- Namespace_N1 (as object property ?)
- functionN1
- Namespace_N2 (as object property ?)
- functionN1
Any information on this topic will be appreciated, thanks :)
Solution 1:[1]
Global object is indeed an object. For example, in the context of a browser, window is the global object. Evaluating var a = 1; in the global scope is equivalent to setting the property a of window to 1, i.e. window.a = 1;.
The documentation of JS_InitStandardClasses says that initialization of a JS context requires you to give an object as the global object. Existing properties of the given object become global variables, and JS_InitStandardClasses will add standard global properties (such as Array, Date, encodeURIComponent) to the given object.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Erman Kadir Kahraman |
