Exnteidng Native Number

4 months ago, I wrote an article extending the native JavaScript Number Object with a format method:

Numbers and Number Format Function

I have revisited that method and also added several other methods to Number.prototype and Number that I find useful. Check out the new Number.js here and the unit test here if you want to double check that it all works well on your favorite browser. Mostly, there is the format method and shortcuts to Math functions.

You may have noticed on Date.js and Number.js that I have been adding an is method to the actual native Object for type detection (not the prototype). This is a compromise that I made with myself, because I do not want a bunch of isType methods in the global namespace, but at the same time I find it tedious to always type "isType(object, type)". So, instead of putting a bunch of isType functions in the global namespace, I am attaching is methods to the native Object for a given type. So, with Number, instead of using "isType(object, number)", I can just write "Number.is(object)". This works for all Object types, including object, because the method is not attached to the prototype Object, thereby not breaking for…in loops. And it is an especially useful shortcut, if your type detection is attached to a nested namespace, such as the YAHOO type detection attached to the "YAHOO.lang" Object.