| 1 | function Animal(name) { |
| 2 | this.name = name; |
| 3 | } |
| 4 | |
| 5 | Animal.prototype.sayHello = function() { |
| 6 | return 'Hello from ' + this.name; |
| 7 | }; |
| 8 | |
| 9 | Animal.prototype.makeNoise = function() { |
| 10 | return this.noise || <1>'<chirp>';</1> |
| 11 | }; |
| 12 | |
| 13 | function Dog(name, breed) { |
| 14 | this.name = name; |
| 15 | this.breed = breed; |
| 16 | this.noise = 'Woof!'; |
| 17 | } |
| 18 | |
| 19 | Dog.prototype = new Animal(); |
| 20 | |
| 21 | <WOOF>Dog</WOOF>.prototype.sayExtendedHello = function() { |
| 22 | return this.sayHello() + ', ' + this.breed; |
| 23 | }; |
| 24 | |
| 25 | Dog.prototype.bark = function() { |
| 26 | return this.noise; |
| 27 | }; |
| 28 | |
| 29 | module.exports = { |
| 30 | Animal: Animal, |
| 31 | Dog: Dog, |
| 32 | }; |