This repository was archived by the owner on Jul 2, 2024. It is now read-only.
Use Date.now() instead of +(new Date())#1
Open
kurtextrem wants to merge 1 commit into
Open
Conversation
|
@kurtextrem I might be wrong, but I think you have changed the |
exports the function Date.now() - a value would only be right once after all. |
|
You are right. My mistake. |
fspoettel
reviewed
Sep 23, 2018
| export const now = () => { | ||
| return +new Date(); | ||
| }; | ||
| export const now = Date.now; |
Contributor
There was a problem hiding this comment.
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 usingDate.now()reduces readability of code since I have to look up hownowis 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
Author
There was a problem hiding this comment.
I agree! However, I don't know if there was a plan to add other functions to now.mjs so I kept it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://jsperf.com/new-date-vs-date-now-vs-performance-now/6
Also saves a few bytes.
Another way would be to just write
export default Date.nowand thenimport {now}=>import now.