I am curious how Underscore's _.now
method is faster than just new Date().getTime()
.
I see the following on their github codebase.
// A (possibly faster) way to get the current timestamp as an integer.
_.now = Date.now || function() {
return new Date().getTime();
};
Can someone please explain what's going on here ?
Well it doesn't have to construct a new Date
object, using the advantage provided by Date.now
. The only problem with that was that browser support, so they included a fallback. It might as well have been a better idea to simply include a polyfill
if (typeof Date.now != "function")
Date.now = function() { return new Date().getTime(); };
and use that instead of advocating their own helper function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With