Skip to content

Instantly share code, notes, and snippets.

@crshmk
Last active January 27, 2019 01:48
Show Gist options
  • Save crshmk/98c719d6d5e37157897bac849b7e7cad to your computer and use it in GitHub Desktop.
Save crshmk/98c719d6d5e37157897bac849b7e7cad to your computer and use it in GitHub Desktop.
A simple chaining strategy
let methods = {
upp: function() {
return Chain(this.x.toUpperCase());
},
slice: function(len) {
return Chain(this.x.slice(len));
},
val: function() {
return this.x
}
}
let Chain = x => ({...methods, x})
Chain('abcde').upp().slice(2).val();
// "CDE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment