In a normal browser javascript environment, you always have the global window
object to fall back on but is there a default accessible global object for the Microsoft JScript Runtime or at least a way to check for one?
Asked
Active
Viewed 818 times
2

SomeShinyObject
- 7,581
- 6
- 39
- 59
-
[A related question](http://stackoverflow.com/questions/4402057/server-side-javascript-classic-asp), albeit about Classic ASP, not WSH. – Cheran Shunmugavel Jan 23 '13 at 07:54
-
1There is more general solution for global context object - http://stackoverflow.com/a/9107491/987850 – 23W Apr 10 '13 at 11:56
1 Answers
4
According to MSDN, there is a Global
object, however a quick test reveals that it is not directly accessible:
WScript.Echo(Global.escape('hello world')); // Error: 'Global' is undefined
What you can do, however, is take advantage of the fact that this
in a global context refers to the global object and save the reference to a variable:
var __global__ = this;
WScript.Echo(__global__.escape('hello world')); // happy times

Cheran Shunmugavel
- 8,319
- 1
- 33
- 40