I try to extend JavaScript Math
. But one thing surprised me.
When I tried to extend it by prototype
Math.prototype.randomBetween = function (a, b) {
return Math.floor(Math.random() * (b - a + 1) + a);
};
In console I have error 'Cannot set property 'randomBetween' of undefined' ...
But if I asigne this function to Math.__proto__
Math.__proto__.randomBetween = function (a, b) {
return Math.floor(Math.random() * (b - a + 1) + a);
};
Then everything works fine.
Can anybody explain me why it works in this way? I appreciate any help.