Arguments against the arguments against adjusting built-in prototypes
That double-negative is not a typo. As stated before, there are unlimited arguments against modifying built-in object prototypes. Some are valid, but most are nothing more than opinions about programming style and convention.
(26).doSomething();
The above statement, agreeably is confusing and probably not a good practice. But, the method I discuss above doesn't allow for such "literal processing", as you are required to formally create a Number object with the new keyword.
var x = new Number(30, Number.units.inches);
This statement can hardly be considered bad style or practice. It uses standard JavaScript object creation syntax, spells out clearly that we are using a modified version of the Number object, and encapsulates the use of units.
At worst, we're trading a questionable JavaScript practice for many rock-solid software construction practices including abstraction and encapsulation.
1 Comment