-
Notifications
You must be signed in to change notification settings - Fork 35
GlobalObject
There is a global object invisibly existed in script context in both JavaScript and ReoScript. As you know you could use an object named 'window' in JavaScript anytime anywhere even you haven't create it. The global object created by script engine when the run-time machine to be created and it was be made can be accessed from anywhere.
window.onload = function() { }
function check_window() {
if (window.opener != null) { }
}
According to Standard ECMAScript, the variable name to accessing the global object could be ignored.
debug.assert( window.opener == opener );
debug.assert( window.onload == onload );
Everything like variable and function defined in most outer scope (not called in function) will be stored and managed as property to the global object.
var a = 10; // where is 'a'?
debug.assert( window.a == a ); // 'a' belongs to 'window'
It's need to notice that the 'var' keyword only does not work when it be executed in most outer scope.
var a = 10; // 'a' stored in global object
function dummy() {
var b = 10; // 'b' is local variable in function scope
}
dummy();
debug.assert( a == b ) // false: there is no 'b' existed
Same rule does apply even a function to be defined:
function hello() {
}
It is same as:
window.hello = function() { }
Does not like JavaScript in Browsers since there is not a Window existed in ReoScript so the global object was be implemented with name 'script'.
In fact in most cases we don't need to use it by specifying its name explicitly. We could just ignore it.