In OOP we have mixed instance data and class functions:
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(this.name + ' makes a noise.');
}
}
const instance = new Animal('Johny');
instance.speak();
In Functional Programming we have instance data and functions seperated:
const createAnimal = (name) => (this_) => {
this_.name = name;
};
const speak = () => (this_) => {
console.log(this_.name + ' makes a noise.');
};
const instance = {};
createAnimal('Johny')(instance);
speak()(instance);