Created
July 6, 2022 11:49
-
-
Save nixjs/2e4364993f7ebeb7bb805d1c874677a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Here's a similar example which uses a class: | |
class AddNumbers { | |
private n: number; | |
constructor(start = 0) { | |
this.n = start; | |
} | |
public add(inc = 1) { | |
this.n = this.n + inc; | |
return this; | |
} | |
public print() { | |
console.log(this.n); | |
return this; | |
} | |
} | |
// Here it is in action: | |
new AddNumbers(2).add(3).add().print().add(1); | |
// This example used the TypeScript | |
// type inference to provide a way to | |
// provide tooling to JavaScript patterns. | |
// For more examples on this: | |
// | |
// - example:code-flow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment