Date.now() in IE8
Been tracking down all kinds of fun issues in ie7/8 browsers recently. Here’s the latest gem.
Date.now()
Date.now()
wasn’t added to the JavaScript spec until ECMAScript 5, which means it won’t work in any version of IE < IE9. (See full table here http://kangax.github.com/es5-compat-table/#showold)
This can be especially tricky to catch since it works just fine in IE9 with IE8 compatibility turned on. Yay IE!
For an easy fix, put the following at the top of your JavaScript context.
Date.now = Date.now || function() { return +new Date; };
Note: +new Date
is shorthand for ToInt32(GetValue(new Date)
or (new Date).valueOf()
see http://es5.github.com/#x11.4.6 <- this might be the best takeaway
sources/links:
http://stackoverflow.com/questions/9430357/please-explain-why-and-how-new-date-works-as-workaround-for-date-now-in
http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript
http://blog.yjl.im/2012/01/datenow-in-ie8-or-before-ie9.html
http://www.microsoft.com/en-us/download/details.aspx?id=11575
- afuchs posted this