Price calculation is an essential part of online stores. The value of a price changes under various conditions, such as adding tips, some percentages off, or tax refund. It is usually re-calculated in run-time once online customers select different plans or purchase extra services. In this sense, a dynamic calculator that is flexible enough to be called by client programmers is appealing.
Air ticket is a typical example. The price at first sight is a raw price, remaining to be updated by adding tax, insurance, etc. In essence, adding features to a price acts like extending properties or methods to an object. Using prototype chain can accomplish it. The code below defines some features at the outset. These “features” can be easily integrated into an existing object by a shared method: addFeature(), which creates a new object inherited from the existing object.