Try wrapping the code in IIFE.
<!DOCTYPE html> <html> <body> <input type=text id=d onkeyup="parsedate()"> </input> <br> <span id=output></span> <script type="text/javascript" src="../../../static/js/date.js"></script> <script> ( function() { parsedate = function() { var input = document.getElementById('d').value; var output = document.getElementById('output'); var d = Date.parse(input); if (d !== null) { output.innerHTML = d.toString(); } else { output.innerHTML = "------" } } }()); </script> </body> </html>
IIFE
(function(){
I wonder why FireFox behaves like this. I know that a few years ago they added security updates that prevent you from overwriting Date.prototype functions, but why can IIFE access this area?
source share