Last active
December 29, 2016 21:23
-
-
Save mickvangelderen/27d8cc73edbe37ef3443a4939fa1f733 to your computer and use it in GitHub Desktop.
This file contains 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 Dog(name) { | |
this.name = name | |
} | |
Dog.prototype.bark = function bark() { | |
return dog_bark(this) | |
} | |
function dog_bark(dog) { | |
return `${dog.name}: Woof!` | |
} | |
// Example use of dog_bark(dog) | |
const spike = new Dog('Spike') | |
const doge = new Dog('Doge') | |
const barks = [ spike, doge ].map(dog_bark) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this implementation,
dog_bark
contains the actual implementation.Dog.prototype.bark
delegates todog_bark
and exists only for convenience.