Previous Chapter's Examples-|-Next Example-|-Return to Chapter Listing

Example 13.1:
Creating Objects


This form displays all the properties for each object created. It uses the dot notation as in object.property:


We created the object instance like this: <SCRIPT LANGUAGE="JavaScript"> <!-- //========================================================================== function product(nam, p) { this.name = nam this.price = p } </SCRIPT> Then we used the new statement to create each object instance: var product1 = new product("TimeSaver", "$23") var product2 = new product("MoneySaver", "$11") var product3 = new product("Time n'MoneySaver", "$99") //========================================================================== //--> </SCRIPT> The object's properties are then displayed using the dot notation: document.write(product1.name + " " + product1.price + "<BR>") document.write(product2.name + " " + product2.price + "<BR>") document.write(product3.name + " " + product3.price + "<BR>")
Previous Chapter's Examples-|-Next Example-|-Return to Chapter Listing