Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leggomuhgreggo/189d5561cf43522eeea4481507637ea6 to your computer and use it in GitHub Desktop.
Save leggomuhgreggo/189d5561cf43522eeea4481507637ea6 to your computer and use it in GitHub Desktop.
Chain: Invocation Function
console.clear();
var Given = function(num) {
this.newNum = num;
this.add = function(num) {
this.newNum = num + this.newNum;
return this;
};
this.subtract = function(num) {
this.newNum = this.newNum - num;
return this;
};
this.multiply = function(num) {
this.newNum = this.newNum * num;
return this;
};
this.divide = function(num) {
this.newNum = this.newNum / num;
return this;
};
this.value = function(num) {
return this.newNum;
};
return this;
};
var given = function(num){
return new Given(num);
}
console.log(given(2).add(2).subtract(2).divide(1).multiply(2).value());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment