I want to write a function which returns an object that will contain a property based on a parameter of the function.
Something like
var my_object_creator = function(prop, value) {
return { prop: value }
}
But the value of the property should not be "prop", but to evaluate the value of prop
, and this is the property name.
I know I can do it like this
var my_object_creator = function(prop, value) {
var t = {};
t[prop] = value;
return t;
}
But I'm wondering whether there's a more elegant way.
Thanks