Equivalent to window in JScript Runtime

强颜欢笑 提交于 2020-01-15 03:17:26

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/14450424/equivalent-to-window-in-jscript-runtime

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