Add the node "global" object to the environment. so that methods declared on it become global to all modules



  • I ran a test getting c# transpiled to JS (via DuoCode) to run last night. Sadly. It expects presence of either nodes "global" or the browsers "document" object.

    I faked it by manually editing its global object to a new JS object. and manually fixing calls to methods it register's "Globally" to instead call based upon that object.

    Example: https://gist.github.com/fusspawn/231beee4c6ddb90bfca3

    Changes made to DuoCode output to get it running are on lines 4-7 of the compiled js and a few commented lines at the end of the compiled js

    15723 -> 15736.

    Please can we have a global object please <3.



  • However. Supprinsgly. Setting up the .NET runtime. and calling the writeline. Takes very little cpu budget..



  • I don't know if this will help you, but objects created without var are visible globally.

    myModule:

    myGlobalVar = "immaglobal";
    var myLocalVar = "immalocal";
    

    myOtherModule:

    console.log(myGlobal); // "immaglobal"
    console.log(myLocal); // error, undefined
    

    main:

    require('myModule');
    require('myOtherModule');
    console.log(myGlobal); // > "immaglobal"
    console.log(myLocal); // > error, undefined
    


  • While my post was true at the time I posted it, this no longer works, which is not awesome. I was using that fact to expose my constructors globally.



  • Thanks for the info. and the update.