Instantiating a javascript object and populating its properties in a single line
Why don't you just do it this way:
var obj = {"city": "A", "town": "B"};
Like so:
var obj = {
city: "a",
town: "b"
}
function MyObject(params) {
// Your constructor
this.init(params);
}
MyObject.prototype = {
init: function(params) {
// Your code called by constructor
}
}
var objectInstance = new MyObject(params);
This would be the prototype way, which i prefere over plain object literals when i need more then one instance of the object.