Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A rule suggesting to replace `` with `Object.hasOwn`

See original GitHub issue

Please describe what the rule should do: Starting V8 v.9.3, can be replaced with an alias/syntax sugar Object.hasOwn, which is much more read-friendly. Further information:

What new ECMAScript feature does this rule relate to? Promoting using of an alias/syntax sugar Object.hasOwn instead of

What category of rule is this? (place an “X” next to just one item)

[ ] Warns about a potential error (problem) [X] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about: The original code:

if (, 'foo')) {
  // `object` has property `foo`.

Should be replaced with:

if (Object.hasOwn(object, 'foo')) {
  // `object` has property `foo`.

Why should this rule be included in ESLint (instead of a plugin)? Applying this rule you can make your application’s code cleaner.

Are you willing to submit a pull request to implement this rule? No.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:12
  • Comments:46 (26 by maintainers)

github_iconTop GitHub Comments

nzakascommented, Aug 17, 2021

@bmish oh cool! We do typically introduce new rules to help people transition from old ways of doing things to new ways of doing things, so we might still end up with it as a core rule. Let’s get a few more thoughts on this. (Especially since there isn’t a great way to discover such rules and plug-ins.)

mdjermanoviccommented, Aug 19, 2021

I’m in favor of this rule, and I think it should also report {}, 'foo').

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.prototype.hasOwnProperty() - JavaScript | MDN
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to ...
Read more >
prefer-object-has-own - ESLint - Pluggable JavaScript Linter
Disallow use of and prefer use of Object.hasOwn(). Fixable. Some problems reported by this rule are automatically ...
Read more >
Object.hasOwn() vs Object.prototype.hasOwnProperty()
hasOwn () returns a boolean indicating whether the specified object has the indicated property as its own property but so does Object.prototype.
Read more >
What is Object.hasOwn() and why should we use it over ...
Object.hasOwn() is intended as a replacement for Object.hasOwnProperty(). In this article, I'll explore their differences and why should one use Object.
Read more >
ECMAScript® 2023 Language Specification - TC39
Toggle "can call user code" annotations u; Navigate to/from multipage m ... hasOwn , a convenient alternative to Object.prototype.hasOwnProperty .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found