@@ -12,6 +12,7 @@ module.exports = Common;
1212
1313 Common . _nextId = 0 ;
1414 Common . _seed = 0 ;
15+ Common . _nowStartTime = + ( new Date ( ) ) ;
1516
1617 /**
1718 * Extends the object in the first argument using the object in the second argument.
@@ -197,7 +198,7 @@ module.exports = Common;
197198 Common . isElement = function ( obj ) {
198199 // http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object
199200 try {
200- return obj instanceof HTMLElement ;
201+ return obj instanceof HTMLElement ;
201202 }
202203 catch ( e ) {
203204 return ( typeof obj === "object" ) &&
@@ -273,26 +274,21 @@ module.exports = Common;
273274 } ;
274275
275276 /**
276- * Returns the current timestamp (high-res if available).
277+ * Returns the current timestamp since the time origin (e.g. from page load).
278+ * The result will be high-resolution including decimal places if available.
277279 * @method now
278- * @return {number } the current timestamp (high-res if available)
280+ * @return {number } the current timestamp
279281 */
280282 Common . now = function ( ) {
281- // http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript
282- // https://gist.github.com/davidwaterston/2982531
283-
284- var performance = window . performance || { } ;
285-
286- performance . now = ( function ( ) {
287- return performance . now ||
288- performance . webkitNow ||
289- performance . msNow ||
290- performance . oNow ||
291- performance . mozNow ||
292- function ( ) { return + ( new Date ( ) ) ; } ;
293- } ) ( ) ;
294-
295- return performance . now ( ) ;
283+ if ( window . performance ) {
284+ if ( window . performance . now ) {
285+ return window . performance . now ( ) ;
286+ } else if ( window . performance . webkitNow ) {
287+ return window . performance . webkitNow ( ) ;
288+ }
289+ }
290+
291+ return ( new Date ( ) ) - Common . _nowStartTime ;
296292 } ;
297293
298294 /**
0 commit comments