Skip to content

Instantly share code, notes, and snippets.

@khaled0fares
Last active July 19, 2016 19:01
Show Gist options
  • Save khaled0fares/cacd21a3a4336121803e0be6fbddbc46 to your computer and use it in GitHub Desktop.
Save khaled0fares/cacd21a3a4336121803e0be6fbddbc46 to your computer and use it in GitHub Desktop.
var Calc = function(init){
this.init = init;
}
Calc.prototype.equals = function(callback){
callback(this.init);
}
Calc.prototype.add = function(val){
this.init += val;
return this;
}
Calc.prototype.minus = function(val){
this.init -= val;
return this;
}
Calc.prototype.multiply = function(val){
this.init *= val;
return this;
}
Calc.prototype.divide = function(val){
this.init /= val;
return this;
}
var calc = new Calc(0);
calc.add(1)
.minus(0)
.multiply(2)
.divide(2)
.equals( function(result){ console.log(result)} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment