Reputation: 13853
I have the following javascript code/object:
config = function(key) {
props = {
svgWidth: 500,
svgHeight: 500,
userUploadImgWidth: 1115,
userUploadImgHeight: 528,
};
return props[key];
}
I'd like to add to the probs
object with additional key value pairs, creating something like this:
config = function(key) {
props = {
svgWidth: 500,
svgHeight: 500,
userUploadImgWidth: 1115,
userUploadImgHeight: 528,
scaledDimensions: {
scaleWidth: 500,
scaleWidth: 232
}
};
return props[key];
}
I can seem to access the props object inside the function, it will return values using config('userUploadImgWidth')
but I want to add new items to the object and just can't figure out the syntax.
Upvotes: 0
Views: 37
Reputation: 338426
Making a function out of that is utterly unnecessary. Are you sure you are not over-engineering something really trivial?
What's wrong with
config = {
svgWidth: 500,
svgHeight: 500,
userUploadImgWidth: 1115,
userUploadImgHeight: 528,
scaledDimensions: {
scaleWidth: 500,
scaleWidth: 232
}
}
and later.
something = config.userUploadImgWidth;
Upvotes: 1