我很好奇Underscore的_.now方法比新的Date().getTime()更快.我在他们的github代码库上看到以下内容.
// A (possibly faster) way to get the current timestamp as an integer._.now = Date.now || function() { return new Date().getTime();};
// A (possibly faster) way to get the current timestamp as an integer.
_.now = Date.now || function() {
return new Date().getTime();
};
有人可以解释一下这里发生了什么吗?
if (typeof Date.now != "function") Date.now = function() { return new Date().getTime(); };
if (typeof Date.now != "function")
Date.now = function() { return new Date().getTime(); };
并使用它而不是提倡自己的帮助函数.