sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

Bundled version contains refetences to undefined self #695

Closed danielo515 closed 3 years ago

danielo515 commented 3 years ago

Hey, this is the heading of the bundled version of sanctuary:

(function(f) {

  'use strict';

  /* istanbul ignore else */
  if (typeof module === 'object' && typeof module.exports === 'object') {
    module.exports = f ();
  } else if (typeof define === 'function' && define.amd != null) {
    define ([], f);
  } else {
    self.sanctuaryShow = f ();
  }

} (function() {

That self on the last else is not defined anywhere, leading to an exception. Is this a bug? Is is happening to me because I have copied sanctuary bundle into an appscript project. Do I need to include anythig else?

davidchambers commented 3 years ago

How does one reference the global object in “appscript”, @danielo515?

danielo515 commented 3 years ago

That is a tricky question, but my guess is that it should be global or maybe window

danielo515 commented 3 years ago

Seems that you just declare stuff on the global scope : https://developers.google.com/apps-script/guides/v8-runtime/migration

I'll make some tests later to see if there is a window or global objects, they are using V8 after all

davidchambers commented 3 years ago

Once you get your hands on the global object you should be able to run something like g.self = g (before loading Sanctuary) to enable Sanctuary to attach itself to the global object.