Skip to main content
Question

Why Function("return this")() is undefined?


shijia.me

Bug here

if code.js of figma plugin includes Function(return this)(), its value is undefined?

It seems like a bug ONLY since 2022.7.14 🤔

this is my code (removed extraneous code)

  let freeSelf = typeof self === 'object' && self && self.Object === Object && self;
  let root = freeGlobal_default || freeSelf || Function('return this')();

  console.log('Function("return this")()', Function('return this')(), Function); // console here

  let root_default = root;
  let Symbol2 = root_default.Symbol; // oops, bug here

Reproducible code

Add these two lines of code to the webpack-react plugin demo to reproduce.

This topic has been closed for replies.

4 replies

shijia.me
  • Author
  • New Participant
  • 15 replies
  • July 15, 2022

Solve this problem by removing developer VM option.


Irvin_Zhan2

Is there a better workaround for this? I’d like to use developer VM but cannot due to this bug. Some packages like lodash need global or this to be defined


Semi_Design_UED-MED

Sorry Irvin, I do not have a better solution for it.


cihad
  • New Participant
  • 5 replies
  • February 25, 2024

Try: const root = eval('this');


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings