When writing the initial tests for the calculator, I noticed that the API for addNumber was a bit horrible.
For example calculator.addNumber(5)()... instead of calculator.addNumber(5)
It's inconsistent with the APIs for the other methods, for example calculator.addPlus() and calculator.equal().
The reason it's like this is because of the front end click bindings data-bind="click: addNumber(5)". The addNumber(5) call must return a function to be executed by the click handler.
We could remove this responsibility from the calculator and put it inside the binding if we rewrote the binding like this data-bind="click: addNumber.bind(null, 5)". That would mean our test code would then be calculator.addNumber(5), which is a lot better.
When writing the initial tests for the calculator, I noticed that the API for addNumber was a bit horrible.
For example
calculator.addNumber(5)()
... instead ofcalculator.addNumber(5)
It's inconsistent with the APIs for the other methods, for example
calculator.addPlus()
andcalculator.equal()
.The reason it's like this is because of the front end click bindings
data-bind="click: addNumber(5)"
. The addNumber(5) call must return a function to be executed by the click handler.We could remove this responsibility from the calculator and put it inside the binding if we rewrote the binding like this
data-bind="click: addNumber.bind(null, 5)"
. That would mean our test code would then becalculator.addNumber(5)
, which is a lot better.