Skip to content

Instantly share code, notes, and snippets.

@alpham
Created May 21, 2016 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpham/47a4bed79c72102c5d619d13ffffd387 to your computer and use it in GitHub Desktop.
Save alpham/47a4bed79c72102c5d619d13ffffd387 to your computer and use it in GitHub Desktop.
'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