Last active
May 3, 2018 21:30
-
-
Save rmacy/9b695476bbc993148cccb9ae3272eb0c to your computer and use it in GitHub Desktop.
About function chaining in Javascript
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
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