Nothing special in Math.roundyou can reproduce this behavior in your own functions:
MyClass = function(){};
MyClass.round = function(x){
if(this instanceof MyClass.round)
throw 'TypeError: MyClass.round is not a constructor';
return Math.round(x);
}
console.log(MyClass.round(0.5));
new MyClass.round();
In fact, you can use a similar pattern to make the keyword newoptional for your class:
function MyClass(){
if(!(this instanceof MyClass))
return new MyClass();
this.x = 5;
}
(new MyClass()).x === MyClass().x;
As for why it newdoes not work with built-in functions and methods, this is by design and documented:
, , , [[Construct]], . - http://es5.github.com/#x15