I'm making a chrome extension and two of the js files are-
- constants.js
- main.js
In constants.js, I've defined an object -
var infoPostJsonParamNames = {"pid" : "PID",
"title" : "title_value",
"price" : "price",
};
And in main.js, I'm using the values in infoPostJsonParamNames as keys of other objects, like -
dataI = new Object();
dataI.infoPostJsonParamNames["title"] = "Title value";
dataI.infoPostJsonParamNames["cost"] = 12.34;
The reason behind doing this is that I've to use the same names of the keys (for example in POST requests), i.e. PID, title_value and price, in many places in the code but it may change in the future, for example, title_value can become TITLE_v.
So I am trying to avoid changing them in many places by changing them in only one place, i.e. in the object infoPostJsonParamNames
.
But doing this gives me the error:
TypeError: Cannot set property 'title' of undefined