var RPNCalculator = function() {
this.stack = [];
this.total = 0;
this.value = function() {
return this.total;
}
this.push = function(val) {
this.stack.push(val);
}
this.pop = function() {
this.stack.pop();
}
this.process = function() {
this.val1 = this.stack.pop();
this.val2 = this.stack.pop();
this.total = 0;
}
this.plus = function() {
this.process();
this.total = this.val1 + this.val2;
this.stack.push(this.total);
}
this.minus = function() {
this.process();
this.total = this.val2 - this.val1;
this.stack.push(this.total);
}
}
How can I make the RPNCalculator object inherit array methods, without creating push and pop methods myself? For example, if I do the following
rpnCalculator = new RPNCalculator();
rpnCalculator.push(2);
it will add the number 2 to the stack array
.stackproperty and instead makeRPNCalculatorinstance array-like.