Skip to content

Instantly share code, notes, and snippets.

@rmacy
Last active May 3, 2018 21:30
Show Gist options
  • Save rmacy/9b695476bbc993148cccb9ae3272eb0c to your computer and use it in GitHub Desktop.
Save rmacy/9b695476bbc993148cccb9ae3272eb0c to your computer and use it in GitHub Desktop.
About function chaining in Javascript
class Animal {
constructor() {
this.pace = null;
}
walk() {
this.pace = "walking";
console.log('our animal is', this.pace);
return this;
}
run() {
this.pace = "running";
console.log('our animal is', this.pace);
return this;
}
}
let ourAnimal = new Animal();
ourAnimal.walk() // -> our animal is walking
ourAnimal.run() // -> our animal is running
ourAnimal.walk().run().walk().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment