1

Given the following code:

eval('(mapping.' + binding.field + ' = eval("extVar") )');

where binding.field = "LPP[0].price" (a string) and extVar is the same value of "LPP[0].price"

How could you program the statement above to end up with:

mapping.LPP[0].price = LPP[0].price;

when mapping.LPP isn't defined yet? This code cycles through the Microsoft JQuery templates pulling variable names as strings from the tempaltes. When we reference properties in arrays, it throws up based on this code. It says that mapping.LPP[0] isn't defined.

6
  • eval within eval o_O Commented Nov 11, 2010 at 18:23
  • 5
    Whatever you are doing, you probably need to be shot for doing it. Anyway, +1 for something ev[ia]l but interesting. Commented Nov 11, 2010 at 18:31
  • What is eval within eval within eval within eval? ... Limbo :D Commented Nov 11, 2010 at 18:47
  • I have no idea what you're trying to do, but it seems very likely that UR DOING IT WRONG!!!111 Commented Nov 11, 2010 at 18:57
  • 4
    I'm pretty sure this summons Cthulhu. Commented Nov 11, 2010 at 20:16

1 Answer 1

1
if(!mapping.LPP) mapping.LPP = [];
mapping.LPP[0].price = LPP[0].price;
Sign up to request clarification or add additional context in comments.

2 Comments

Very cool. I went nuts with this answer on another question, which is also similar, but asks how to remove the eval statement from the code. stackoverflow.com/questions/4159747/…
Glad I could help :-) And as an aside, Invader Zim is awesome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.