Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Use Date.now() instead of +(new Date()) #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/now.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
* @private
* @return {number} The current date timestamp
*/
export const now = () => {
return +new Date();
};
export const now = Date.now;
Copy link
Contributor

@fspoettel fspoettel Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would make sense to remove lib/now.mjs at this point since it just re-declares browser functionality. Instead, I'd argue for calling Date.now() directly when needed:

  • Importing now() instead of using Date.now() reduces readability of code since I have to look up how now is implemented when reading code calling the func
  • A module will lead to some overhead when used with common module bundlers (e.g. webpack), negating the bytes saved with declaring it here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! However, I don't know if there was a plan to add other functions to now.mjs so I kept it.