MV The function object

I am currently trying to develop a certain plugin and when I had the console open and entered scripts in the console to test it's functionality I noticed big performance issue. Without the console open it seemed to run smoothly. I was pretty sure the issue came from using eval().
After that I've watched a video about the function object. And the author of that video said, that the function object creates it's own global space and does not know variables outside of it, so I just want to know why the following works, at least in MV:

1630954411334.png

I am actually glad, that it works, because this made my plugin to be changed from eval() to the function object easy without needing to do workarounds around the own global space restriction. The performance issue seem to be gone aswell.
The function you created works simply because inside it you are doing operations using global variables (window properties): a, b, $gameVariables, these are all global and are in the same scope as your test functions.
And for d, it works like that because its local arguments a and b take priority over the global variables with those identifiers.

a and b are global because they are not enclosed within a function.

There is only one global scope. The Function constructor does not remember the scope in which it was called, it simply creates a new, global function.
I've found out now, that the video creator used node.js and here variables declared globally within the *.js file are actually not in the global scope, but local to the module as described in:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
But in web browsers and RMMV it works like I want it to work.

Original thread: https://forums.rpgmakerweb.com/threads/the-function-object.140213/