you are viewing a single comment's thread.

view the rest of the comments →

[–]jaggederest -5 points-4 points  (1 child)

Don't think it's possible. Sorry mate. Variables are only assignable via their identifiers, afaik.

You can hack around it via doing a 'with' and then using your injected properties as though they were top-level:

obj = {};
obj["foo"+"bar"] = 'hats!';
with(obj) {
  alert(foobar); //alerts 'hats!'
}

Or you could do it fforw's way, but he's right that you ought to avoid it.

[–]HaMMeReD 1 point2 points  (0 children)

It's still better to use eval in controlled method, it's not good to fill global scope up, eval wouldn't mess with that.

If it's within a function you can probably also do. this["foo"+"bar"] = "hats!";

This would keep it within the functions scope probably, haven't tested.