If you store a reference to the original parseInt
function, you can overwrite it with your own implementation;
(function () {
var origParseInt = window.parseInt;
window.parseInt = function (val, radix) {
if (arguments.length === 1) {
radix = 10;
}
return origParseInt.call(this, val, radix);
};
}());
However, I strongly recommend you don't do this. It is bad practise to modify objects you don't own, let alone change the signature of objects you don't own. What happens if other code you have relies on octal being the default?
It will be much better to define your own function as a shortcut;
function myParseInt(val, radix) {
if (typeof radix === "undefined") {
radix = 10;
}
return parseInt(val, radix);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…