Last active
July 4, 2020 15:45
-
-
Save julienetie/f716993319e91b7b3d0326b5dcb09fb0 to your computer and use it in GitHub Desktop.
ho-js-9.js
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
/* Pseudo-Functional JavaScript */ | |
// This is equivalent to the higer-order example, just with slightly different syntax | |
const animal = name => ({ | |
speak: () => console.log(`${name} makes a noise.`) | |
}); | |
const dog = (parent, name) => { | |
return { | |
...parent(name), | |
...({ | |
speak() { | |
console.log(`${name} barks.`) | |
} | |
}) | |
}; | |
}; | |
/* | |
const d = dog(animal, 'Mitzie') | |
d.speak(); // Mitzie barks. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment