In many compiled Javascript modules, somewhere in the preamble there is a call to Function('return this')()to get a global object. I work in an interpreter environment where the use of a constructor Function(together with eval) is prohibited for security reasons. I replaced the above code with (function(){return this})(), and everything seems to work.
Is this a safe replacement? Are there any cases where this may fail? Why do most compiled JS modules prefer a constructor anyway?
source
share