Skip to content

Instantly share code, notes, and snippets.

@WillsonSmith
Last active August 29, 2015 14:18
Show Gist options
  • Save WillsonSmith/7340c92f444c3e0893e2 to your computer and use it in GitHub Desktop.
Save WillsonSmith/7340c92f444c3e0893e2 to your computer and use it in GitHub Desktop.
do the more maths from base
(function() {
"use strict";
var assign = require("lodash.assign"),
mathPrototype = {
total: 0,
add: function add(number) {
this.total += number;
return this;
},
subtract: function subtract(number) {
this.total -= number;
return this;
},
get: function logTotal() {
return this.total;
}
},
advancedMathPrototype = {
pow: function pow(number) {
this.total = Math.pow(this.total, number);
return this;
}
};
advancedMathPrototype = assign(Object.create(mathPrototype), advancedMathPrototype);
function calculate(base, prototype) {
var functions = Object.create(prototype);
functions.total = base || 0;
return functions;
}
var calculator = calculate(0, mathPrototype),
advancedCalculator = calculate(0, advancedMathPrototype);
calculator.add(5).add(5).subtract(5);
advancedCalculator.add(5).add(5).pow(2);
console.log(calculator.get());
console.log(advancedCalculator.get());
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment