Last active
May 8, 2018 00:36
-
-
Save alvarezmauro/959b132b931fe08b71ee043b6f4ee350 to your computer and use it in GitHub Desktop.
JS design pattern - Chaning
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
var objWithChaining = function objWithChaining(someValue){ | |
var self = this; // Capture "this" object because the caller may not be trusted ಠ_ಠ | |
this.methodOne = function methodOne(methodParam){ | |
// method implementation | |
return self; | |
} | |
this.methodTwo = function methodTwo(methodParam){ | |
// method implementation | |
return self; | |
} | |
this.methodThree = function methodThree(methodParam){ | |
// method implementation | |
return self; | |
} | |
this.callbackMethod = function callbackMethod(callback){ | |
callback(someValue); | |
return self; | |
} | |
} | |
new objWithChaining(0) | |
.methodOne(10) | |
.methodTwo(100) | |
.methodThree(1000) | |
.callbackMethod(function(someValue){ | |
console.log(someValue) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment