Last active
January 27, 2019 01:48
-
-
Save crshmk/98c719d6d5e37157897bac849b7e7cad to your computer and use it in GitHub Desktop.
A simple chaining strategy
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
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