Created
July 9, 2020 03:49
-
-
Save gpDA/fb91f6ed6ab27f8a1049292a36697bb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function MacBook() { | |
| this.cost = function () { return 997; } | |
| this.screenSize = function () { return 11.6; }; | |
| } | |
| // Decorator 1 | |
| function Memory ( macbook ) { | |
| var v = macbook.cost(); | |
| macbook.cost = function() { | |
| return v + 75; | |
| }; | |
| } | |
| // Decorator 2 | |
| function Engraving ( macbook ) { | |
| var v = macbook.cost(); | |
| macbook.cost = function() { | |
| return v + 200; | |
| }; | |
| } | |
| // Decorator 3 | |
| function Insurance ( macbook ) { | |
| var v = macbook.cost(); | |
| macbook.cost = function() { | |
| return v + 250; | |
| }; | |
| } | |
| var mb = new MacBook(); | |
| Memory( mb ); | |
| Engraving( mb ); | |
| Insurance( mb ); | |
| console.log(mb.cost()); // 1522 | |
| console.log(mb.screenSize()); 11.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment