victor
victor copied to clipboard
toFixed converts x and y coordinates to strings
Since Victor#toFixed() uses Number#toFixed() under the hood, it is turning the x and y coordinates of the vector into strings: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
Although you are correct, I would argue that it makes sense to keep the API consistent with the JavaScript one. I agree that Number#toFixed is kind of annoying, but when I call it I expect a string.
The problem is that it will break all further functionality of the vector/point, since all other functions are expecting numbers, not strings.
If you want to follow Number#toFixed() you should return a new object, since Number#toFixed() does not change the object itself - it returns a new string.
var a = 10; var b = a.toFixed();
a is still a number.. b is "10"
Good point. How do you feel about keeping #toFixed as returning a string (and change it to stop it mutating). And then adding a #roundToDecimalPlaces (or similar) method to allow for the functionality that you want?
Sounds perfect!