I have extended javascripts core functionality by creating a few functions that were useful to me. When creating test cases for a function today I started wondering which way is the best to extend javascripts functionality for integer numbers. Using Number.prototype, or the Math object.
Number.prototype.sqr = function () {
return this * this;
};
var test1 = (6).sqr();
alert("This is 36: " + test1);
OR
Math.sqr = function (num) {
return num * num;
};
var test2 = Math.sqr(6);
alert("This is 36: " + test2);
These two examples could be switched around for any integer type function that you would like to create, so which should be used?