Javascript eval on global scope?

(function(){
    eval.apply(this, arguments);
}(a,b,c))

This will invoke eval using the global object, window in browsers, as the this argument passing any arguments you’ve passed into the anonymous function.

eval.call(window, x, y, z) or eval.apply(window, arguments) is also valid if you’re certain window is the global object. This isn’t always true, however. For instance, the global object in a Node.js script is process if I remember correctly.

Leave a Comment