Skip to main content
shijia.me
Active Member
July 14, 2022
Question

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

  • July 14, 2022
  • 4 replies
  • 742 views

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
shijia.meAuthor
Active Member
July 15, 2022

Solve this problem by removing developer VM option.

Irvin_Zhan2
January 31, 2023

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
January 31, 2023

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

cihad
New Participant
February 25, 2024

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