Created
May 21, 2016 21:37
-
-
Save alpham/47a4bed79c72102c5d619d13ffffd387 to your computer and use it in GitHub Desktop.
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
'use stirct'; | |
function calculator(){ | |
this.ans = 0; | |
var self = this; | |
this.add = add; | |
this.miniz = miniz; | |
this.div = div; | |
this.multi = multi; | |
this.result = result; | |
function add(num){ | |
self.ans = self.ans + num; | |
return self; | |
} | |
function miniz(num){ | |
self.ans = self.ans - num; | |
return self; | |
} | |
function div(num){ | |
self.ans = self.ans / num; | |
return self; | |
} | |
function multi(num){ | |
self.ans = self.ans * num; | |
return self; | |
} | |
function result(){ | |
return self.ans; | |
} | |
} | |
var cal = new calculator; | |
cal.add(10).add(20).miniz(2).div(2); | |
console.log(cal.result()); // result 14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment