Decorator mode example implemented by node.js

This example tells the decorative model implemented by Node.js. Share to everyone for reference, as follows:

The implementation of the decorator mode is more emphasized in combination of classes rather than by inheritance. This enhances flexibility. In Node.js, you can be implemented by a Call function. The Call function can call another member function in an object to reach a combination of classes in this sense.

VAR UTIL = Require (‘Util’); var beverage = function () {var description = “unkown beverage” this.getdescription = function () {Return Description; }} function Espresso () {Beverage.call (this); this.description = “Espresso”;} util.inherits (Espresso, Beverage); Espresso.prototype.cost = function () {return 1.99;} function HouseBlend () {Beverage.call (this); this.description = “house blend coffee”;} util.inherits (houseblend, beverage); houseblend.prototype.cost = function () {return .89;} function mocha (beverage) {THIS .beverage = beverage;}; mocha.prototype.getdescription = function () {RETurn this.beverage.getdescription () + “, mocha”;} mocha.prototype.cost = function () {return 0.20 + this.beverage.cost ();} function whip (beverage) {this.beverage = beverage; ; Whip.Prototype.getdescription = function () {return this.beverage.getdescription () + “, whip”;} whip.prototype.cost = function () {return 0.40 + this.beverage.cost ();} var beverage = new Espresso (); console.log (beverage.getDescription () + “$” + beverage.cost ()); var beverage2 = new HouseBlend (); beverage2 = new Mocha (beverage2); beverage2 = new Mocha (beverage2) Beverage2 = new whip (beverage2); console.log (beverage2.log (beverage2.description2.cost ());
   
It is desirable to be described herein. Everyone node.js program is helpful.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment