Datejs - problem from 12:00

I really don't know what I'm doing wrong here. I can't get Datejs to parse "12:00 pm" correctly, however, it seems to work fine on other dates. Below is a clip from the Firefox debugger:

enter image description here

+6
source share
2 answers

Download the latest version of Datejs from SVN, not the version in the download section.

+16
source

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(){ //code }()); 

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?

0
source

Source: https://habr.com/ru/post/891143/


All Articles