Is there a way I can do all of this in a constructor?
obj = new Object(); obj.city = \"A\"; obj.town = \"B\";
try this:
function MyObject(city, town) { this.city = city; this.town = town; } MyObject.prototype.print = function() { alert(city + " " + town); } obj = new MyObject("myCity", "myTown"); obj.print();