Okay so I wrote this simple javascript function to make my code more readable:
Number.prototype.isBetween=function(a,b){
return(this>=a&&this<b);
};
Now this turns out to be VERY slow: I tried this "benchmark" (I don't really know how to properly do this stuff but this proves my point either way):
var res=0;
var k=20;
var t=new Date().getTime();
for(var i=0;i<10000000;i++){if(k.isBetween(13,31)){res++;}}
console.log(new Date().getTime()-t);
versus
var res=0;
var k=20;
var t=new Date().getTime();
for(var i=0;i<10000000;i++){if(k>=13&&k<31)){res++;}}
console.log(new Date().getTime()-t);
and the first script takes about 3000ms in chrome (and chrome is what I'm using and what I'm interested in), whereas the second script takes only 24ms - a whole factor 125 faster. Is extending the existing classes javascript provides just a really bad idea? What is going on here?