How to override a JavaScript function

I'm trying to override a built in parseFloat function in JavaScript.

How would I go about doing that?


Solution 1:

var origParseFloat = parseFloat;
parseFloat = function(str) {
     alert("And I'm in your floats!");
     return origParseFloat(str);
}

Solution 2:

You can override any built-in function by just re-declaring it.

parseFloat = function(a){
  alert(a)
};

Now parseFloat(3) will alert 3.