Rand
Rand

Reputation: 105

How can I restore an overwritten native function

Just a though experiment, say I decided to prevent eval() from being run in my node application, and I ran added something like:

global['eval'] = function(args){ this.console.log(`eval attempted: ${args}`); }

Is there any way to restore eval without restarting the application?

Upvotes: 0

Views: 102

Answers (1)

Nicholas Tower
Nicholas Tower

Reputation: 85132

If you save a reference to the function, yes.

const originalEval = global.eval;
global.eval = function(args){ this.console.log(`eval attempted: ${args}`);}

function restore() {
  global.eval = originalEval;
}

Upvotes: 4

Related Questions