Skip to content

Instantly share code, notes, and snippets.

@julienetie
Last active July 4, 2020 15:45
Show Gist options
  • Save julienetie/f716993319e91b7b3d0326b5dcb09fb0 to your computer and use it in GitHub Desktop.
Save julienetie/f716993319e91b7b3d0326b5dcb09fb0 to your computer and use it in GitHub Desktop.
ho-js-9.js
/* 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