File tree 2 files changed +14
-9
lines changed 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ $(document).ready(function() {
49
49
} ) , "should produce a random number when passed `Number.MAX_VALUE`" ) ;
50
50
} ) ;
51
51
52
+ test ( "now" , function ( ) {
53
+ var diff = _ . now ( ) - new Date ( ) . getTime ( ) ;
54
+ ok ( diff <= 0 && diff > - 5 , "Produces the correct time in milliseconds" ) ; //within 5ms
55
+ } ) ;
56
+
52
57
test ( "uniqueId" , function ( ) {
53
58
var ids = [ ] , i = 0 ;
54
59
while ( i ++ < 100 ) ids . push ( _ . uniqueId ( ) ) ;
Original file line number Diff line number Diff line change 20
20
// Save bytes in the minified (but not gzipped) version:
21
21
var ArrayProto = Array . prototype , ObjProto = Object . prototype , FuncProto = Function . prototype ;
22
22
23
- //use the faster Date.now if available.
24
- var getTime = ( Date . now || function ( ) {
25
- return new Date ( ) . getTime ( ) ;
26
- } ) ;
27
-
28
23
// Create quick reference variables for speed access to core prototypes.
29
24
var
30
25
push = ArrayProto . push ,
679
674
var previous = 0 ;
680
675
options || ( options = { } ) ;
681
676
var later = function ( ) {
682
- previous = options . leading === false ? 0 : getTime ( ) ;
677
+ previous = options . leading === false ? 0 : _ . now ( ) ;
683
678
timeout = null ;
684
679
result = func . apply ( context , args ) ;
685
680
context = args = null ;
686
681
} ;
687
682
return function ( ) {
688
- var now = getTime ( ) ;
683
+ var now = _ . now ( ) ;
689
684
if ( ! previous && options . leading === false ) previous = now ;
690
685
var remaining = wait - ( now - previous ) ;
691
686
context = this ;
712
707
return function ( ) {
713
708
context = this ;
714
709
args = arguments ;
715
- timestamp = getTime ( ) ;
710
+ timestamp = _ . now ( ) ;
716
711
var later = function ( ) {
717
- var last = getTime ( ) - timestamp ;
712
+ var last = _ . now ( ) - timestamp ;
718
713
if ( last < wait ) {
719
714
timeout = setTimeout ( later , wait - last ) ;
720
715
} else {
1111
1106
return min + Math . floor ( Math . random ( ) * ( max - min + 1 ) ) ;
1112
1107
} ;
1113
1108
1109
+ //use the faster Date.now if available.
1110
+ _ . now = _ . getTime = ( Date . now || function ( ) {
1111
+ return new Date ( ) . getTime ( ) ;
1112
+ } ) ;
1113
+
1114
1114
// List of HTML entities for escaping.
1115
1115
var entityMap = {
1116
1116
escape : {
You can’t perform that action at this time.
0 commit comments