eval … everywhere?

Harvested from an Opera bug report, here is another interesting surprise from Gecko internals: Object.prototype.eval . It's like a normal eval() but in the scope of that object. In other words, doing


is practically the same as doing


(Before you ask, the best practice would be to say either




Using eval should be avoided and generally can be avoided without problems. So don't let me catch you using any of the two first snippets on a production site!)

So hey Gecko, where did this come from? Is it something we should copy and implement or something we should scorn and point fingers at?

7 thoughts on “eval … everywhere?

  1. dwright: thank you! :)xErath: don't know – I have to check. That test suite was buggy when I tried running it in Opera, but that's a while ago and I reported some issues that probably got fixed.

  2. dwright: my Firefox/ certainly has it. Should I bug this without testing in a nightly build though? I don't mind filing it but wouldn't go as far as downloading a nightly build – more than enough of test builds from Opera so no, thanks.. 🙂

  3. javascript:var foo=new Object();foo.bar="foobar";alert(foo.eval('b'+'ar'));Shows "foobar" in a nightly (specifically Minefield 3.0a1/20060908). You should file that bug.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s