
Figure 9.3: The result in Netscape
In this example, the constructor for Product declares two properties (name
and prices) and one method (toXML).
function Product(name,prices)
{
this.name = name;
this.prices = prices;
this.toXML = product_toXML;
}
These objects are created with the new operator like built-in JavaScript
objects:
var product = new Product(name,prices);
JavaScript objects are used like built-in objects:
xmlCode += products[i].toXML();
Writing XML
The Product and Price objects are XML-aware because they know how to
save (serialize) themselves as XML objects through the toXML() function.
The
makeXML() function is trivial: It iterates over the list ...