Previous Example-|-Next Example-|-Return to Chapter Listing

Example 13.3:
Creating Methods

This form displays all the properties for each object created and uses the OrderAmount() method to calculate the total cost of the order. This is order.ProductType.price multiplied times order.quantity.


This page uses the following to create the objects: <SCRIPT LANGUAGE="JavaScript"> <!-- //========================================================================== function OrderAmount() { return (this.quantity * this.ProductType.price) } //========================================================================== function product(nam, p) { this.name = nam this.price = p } //========================================================================== function order(custname, prod, numbof) { this.customer = custname this.ProductType = prod this.quantity = numbof this.OrderDate = new Date() this.OrderAmount = OrderAmount } var product1 = new product("TimeSaver", 23) var product2 = new product("MoneySaver", 11) var product3 = new product("Time n'MoneySaver", 99) var order1 = new order("Mr Brainless", product1, 5) var order2 = new order("Mr Bonkers", product3, 22) var order3 = new order("Mr Bozo", product2, 1) //========================================================================== //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing