How to execute "eval" without writing "eval" in JavaScript
Posted
by Infinity
on Stack Overflow
See other posts from Stack Overflow
or by Infinity
Published on 2010-02-03T20:50:08Z
Indexed on
2010/05/21
8:30 UTC
Read the original article
Hit count: 653
Here's the deal, we have a big JS library that we want to compress, but YUI compressor doesn't fully compress the code if it finds an "eval" statement, out of fear that it will break something else. That's great and all, but we know exactly what is getting eval'd, so we don't want it to get conservative because there's an eval statement in MooTools JSON.decode
So basically the question is, is there any alternative (maybe creative) way of writing a expression that returns the eval function? I tried a few, but no dice:
window['eval'](stuff);
window['e'+'val'](stuff);
// stuff runs in the global scope, we need local scope
this['eval'](stuff);
// this.eval is not a function
(new Function( "with(this) { return " + '(' + stuff + ')' + "}"))()
// global scope again
Any ideas? Thx
© Stack Overflow or respective owner