Created
April 2, 2018 22:23
-
-
Save leggomuhgreggo/6b9f0c779929e093aabd5e5664bf4c16 to your computer and use it in GitHub Desktop.
Chain: Goofy Approach
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
console.clear(); | |
var Given = function(num) { | |
this.newNum = num || 0; | |
this.add = function(num) { | |
this.newNum = this.newNum + num; | |
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; | |
}; | |
var n = { __proto__: Given.prototype }; | |
return function() { | |
Given.apply(n, arguments); | |
return n; | |
}; | |
}; | |
var given = new Given(); | |
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