NeWorld

Javascript: sukuriam naują kintamąjį per eval

by neworld on Kov.11, 2008, under Javascript, Programavimas

Man iškilo problema, prisireikė sukurti kintamąjį per eval.

[code lang="javascript"]eval("new a=5;");[/code]

Neveikia (spėju todė, kad sukuriamas ne globalus kintamasis). Ilgai googlinau, kol šovė į galvą pabandyti sukurti per objektą. Dar pagoglines suradau, kad globalūs kintamieji randasi window objekte. Taigi pabandžiau:

[code lang="javascript"]eval("window.a=5;");[/code]

Ir vualia, veikia. Kas keisčiausia, jog kurti kintamojo nebereikia, bet viskas veikė ant Firefox 2.0.0.12, IE7 ir operos 9.26.

  Balsuoti

Leave a Reply

 

You need to log in to vote

The blog owner requires users to be logged in to be able to vote for this post.

Alternatively, if you do not have an account yet you can create one here.

Powered by Vote It Up

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...