Math.func to Number.func
Posted: Sat Nov 08, 2008 3:32 pm
I'd like to know what you think of this approach to implementing mathematical functions in JavaScript. Rather then Math.pow(base, exponent) wouldn't it be easier, and make more sense, to write (base).pow(exponent)? It is really easy to create such methods.
With this I could write:
This feels more object oriented in a way, and it could be done with every math function.
If this was in a library or API of some kind how would you rate this? Is it good or bad? Explain why you think it is what you think it is.
Thanks for reading my brief and arguably uninteresting post.
Code: Select all
Number.prototype.pow = function(e) { return Math.pow(this, e); };
Code: Select all
var base = 10;
base.pow(6);
(5).pow(2);
If this was in a library or API of some kind how would you rate this? Is it good or bad? Explain why you think it is what you think it is.
Thanks for reading my brief and arguably uninteresting post.