Is there a way I can do all of this in a constructor?
obj = new Object();
obj.city = \"A\";
obj.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.