Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use Object.hasOwnProperty #68

Merged
merged 1 commit into from
Jul 19, 2020
Merged

Conversation

curbengh
Copy link
Contributor

skipduplicate key is only checked for its existence, its value is actually not relevant to its purpose, even when the value is undefined.

If the key is there, its value is never undefined though, but rather boolean, string or number.

$ hexo migrate rss path.xml --skipduplicate => args: { _: ['path.xml'], skipduplicate: true }
$ hexo migrate rss path.xml --skipduplicate undefined => args: { _: ['path.xml'], skipduplicate: 'undefined' }
$ hexo migrate rss path.xml --skipduplicate 123 => args: { _: ['path.xml'], skipduplicate: 123 }


Object.prototype.hasOwnProperty is indeed slower than typeof, but it only runs once so it shouldn't cause noticeable latency. Thus, in this use case, better accuracy can be achieved without performance impact.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.833% when pulling 3cfcb0d on curbengh:hasownprop into f53388d on hexojs:master.

@curbengh curbengh merged commit 09a55d6 into hexojs:master Jul 19, 2020
@curbengh curbengh deleted the hasownprop branch July 19, 2020 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants