Re: How can I call variable in script like this global.var

muhammad sami <[email protected]> Mon, 1 Apr 2019 09:24:57 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On Monday, April 1, 2019 at 6:03:53 PM UTC+2, Boris Zbarsky wrote:
> On 4/1/19 11:41 AM, muhammad sami wrote:
> > noname:1:ReferenceError: global is not defined
> 
> Right, because you never defined it.  You could do:
> 
>    run(cx, e.dialog, "x");
> 
> or
> 
>    run(cx, e.dialog, "this.x");
> 
> depending on the semantics you want.  Or if you have a new enough 
> SpiderMonkey (corresponding to Gecko 65 or later):
> 
>    run(cx, e.dialog, "globalThis.x");
> 
> -Boris
Hi Boris 
    Thanks for quick response. I'm using spidermonkey 45. can I rename the global object as in v8. I have tried 
                   run(cx, e.dialog, "globalThis.x"); 
but still same output. 
noname:1:ReferenceError: globalThis is not defined 

please consider that I'm new to spidermonkey so parden me if I'm missing something obvious. 

My main goal is to achieve scoping in vxml interpreter which allow users to run scripts as follow 

<?xml version="1.0" encoding="UTF-8"?> 
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.w3.org/2001/vxml 
   http://www.w3.org/TR/voicexml20/vxml.xsd"> 
  <form> 
    <script> 
      var now = new Date(); <!-- this has a dialog scope--> 
    </script> 
    <var name="seconds" expr="now.getSeconds()"/> <!--this has a dialog scope-> 
    <block> 
      <var name="now" expr="new Date()"/><!--this has an anonymous scope --> 
      <script> 
        var current = now.getSeconds();   <!-- "now" in the anonymous scope --> 
        var approx = dialog.now.getSeconds();<!-- "now" in the dialog scope --> 
      </script> 
    </block> 
  </form> 
</vxml> 

for more info please read this 
https://stackoverflow.com/questions/55442153/how-to-specify-script-execution-scope-in-spidermonkey