Why are you using eval
at all? You can do it exactly the same way you'd do it in JavaScript:
foo = 'asdf'
h = { }
h[foo] = 'bar'
That translates to this JavaScript:
var foo, h;
foo = 'asdf';
h = {};
h[foo] = 'bar';
And the result is that h
looks like {'asdf': 'bar'}
.