Access the local function of the eval function

Please consider the following two code snippets:

(function f() { var x; try { eval("x"); console.log('No error!'); } catch (e) { console.log('Error!'); } }(eval)) 

and

 (function f(eval) { var x; try { eval("x"); console.log('No error!'); } catch (e) { console.log('Error!'); } }(eval)) 

First print No error! , the second is Error! . Is there a way to access the "local eval " inside the function area for which eval is one of the arguments?

-1
source share
2 answers

Global functions are part of the window object. Call window.eval() instead.

0
source

You can still use

 window.eval() 

in this case

0
source

Source: https://habr.com/ru/post/907702/


All Articles