Skip to content

Instantly share code, notes, and snippets.

@nixjs
Created July 6, 2022 11:49
Show Gist options
  • Save nixjs/2e4364993f7ebeb7bb805d1c874677a9 to your computer and use it in GitHub Desktop.
Save nixjs/2e4364993f7ebeb7bb805d1c874677a9 to your computer and use it in GitHub Desktop.
// 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