Closed tomhicks-bsf closed 9 years ago
Doesn't this lock the timestamp to a single value? Or am I missing something? now
doesn't return a function, but an actual value.
> var now = (function() { return +new Date; })()
undefined
> now
1432197198304
> now
1432197198304
> now
1432197198304
It returns a function that will call +new Date. You're just returning the value, not a function:
var now = (function () {
return function () { return +new Date; };
})();
as opposed to
var now = (function () {
return return +new Date;
})();
So the now
function will be one of two functions: the IE one or the proper one.
Ah, yes, of course. Didn't look close enough. Looks good :+1: Thanks!
I'm not sure if this code is hit often enough to make this micro-optimisation worth it, but we can generate the now function at load-time rather than checking how to get it every time we call it.