Skip to content
Browse files

Use Date.now() instead of +new Date

  • Loading branch information...
1 parent 8928f97 commit 8f1c63a92bf4124c48048a75c222172ac1baa13f @joelfillmore joelfillmore committed Feb 13, 2013
Showing with 12 additions and 5 deletions.
  1. +12 −5 PxLoader.js
View
17 PxLoader.js
@@ -27,7 +27,7 @@ function PxLoader(settings) {
var entries = [],
// holds resources to be loaded with their status
progressListeners = [],
- timeStarted, progressChanged = +new Date;
+ timeStarted, progressChanged = Date.now();
/**
* The status of a resource
@@ -123,7 +123,7 @@ function PxLoader(settings) {
};
this.start = function(orderedTags) {
- timeStarted = +new Date;
+ timeStarted = Date.now();
// first order the resources
var compareResources = getResourceSort(orderedTags);
@@ -142,7 +142,7 @@ function PxLoader(settings) {
var statusCheck = function() {
var checkAgain = false,
- noProgressTime = (+new Date) - progressChanged,
+ noProgressTime = Date.now() - progressChanged,
timedOut = (noProgressTime >= settings.noProgressTimeout),
shouldLog = (noProgressTime >= settings.loggingDelay);
@@ -201,7 +201,7 @@ function PxLoader(settings) {
return;
}
entry.status = statusType;
- progressChanged = +new Date;
+ progressChanged = Date.now();
var numResourceTags = resource.tags.length;
@@ -279,7 +279,7 @@ function PxLoader(settings) {
return;
}
- var elapsedSeconds = Math.round((+new Date - timeStarted) / 1000);
+ var elapsedSeconds = Math.round((Date.now() - timeStarted) / 1000);
window.console.log('PxLoader elapsed: ' + elapsedSeconds + ' sec');
for (var i = 0, len = entries.length; i < len; i++) {
@@ -376,6 +376,13 @@ if (typeof define === 'function' && define.amd) {
});
}
+// Date.now() shim for older browsers
+if (!Date.now) {
+ Date.now = function now() {
+ return +(new Date);
+ };
+}
+
// shims to ensure we have newer Array utility methods
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
if (!Array.isArray) {

0 comments on commit 8f1c63a

Please sign in to comment.
Something went wrong with that request. Please try again.