93node
_.now()
參數jquery
返回值npm
(number): 返回時間戳ui
例子this
_.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); // => Logs the number of milliseconds it took for the deferred invocation.
源代碼:spa
/** * lodash (Custom Build) <https://lodash.com/> * Build: `lodash modularize exports="npm" -o ./` * Copyright jQuery Foundation and other contributors <https://jquery.org/> * Released under MIT license <https://lodash.com/license> * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors */ /** Detect free variable `global` from Node.js. */ var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; //檢查nodejs環境中的global對象 /** Detect free variable `self`. */ var freeSelf = typeof self == 'object' && self && self.Object === Object && self; //檢查self對象 /** Used as a reference to the global object. */ var root = freeGlobal || freeSelf || Function('return this')(); //對全局對象的引用 /** * Gets the timestamp of the number of milliseconds that have elapsed since * the Unix epoch (1 January 1970 00:00:00 UTC). * * @static * @memberOf _ * @since 2.4.0 * @category Date * @returns {number} Returns the timestamp. * @example * * _.defer(function(stamp) { * console.log(_.now() - stamp); * }, _.now()); * // => Logs the number of milliseconds it took for the deferred invocation. */ //獲取從Unix紀元(1970年1月1日)開始一直到如今的經歷的時間的毫秒數 var now = function() { return root.Date.now(); }; module.exports = now;