how can you make an prototype on an Integer?
Integer.prototype.num = function(dec){
return number_format(this.toString(), dec);
}
Javascript has no integral types (Integer
). Only floating point numbers (try typeof 3
. Returns Number
).
So you could use something like:
Number.prototype.myfunc = function() { }
As Felix Kling mentioned in the comment, extending Javascript built in objects using the .prototype
property is usually not a good idea. The new extension applies automatically to all objects of this type - including those already instantiated and the nones that will be created by code other than yours. Thus, it might interfere with what some other code is expecting of the Number object.