Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add `Object.hasOwn` to Section 3.7 (Object.prototype methods)

未关闭
#2,606 4 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
48/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
停滞
技术栈
eslint, javascript
领域
documentation

调研方向

从 JavaScript 风格指南中的第 3.7 节“Object.prototype methods”开始,并查阅有关 Object.hasOwn 和 prefer-object-has-own 的链接 MDN 和 ESLint 文档。更新该节的措辞和示例以涵盖 Object.hasOwn,然后验证这些指导准确反映所引用的浏览器支持情况和 ESLint 规则。

由索引模型根据 Issue 内容生成。

描述

pull request wanted

Hello, it seems that Object.hasOwn is now available in most major browsers (https://caniuse.com/mdn-javascript_builtins_object_hasown), so it might be worth adding it to section 3.7.
It seems to be recommended as a replacement for Object.hasOwnProperty (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn), so the section could be changed to something like this:

  • 3.7 Do not call Object.prototype methods directly, such as hasOwnProperty, propertyIsEnumerable, and isPrototypeOf. eslint: no-prototype-builtins

    Why? These methods may be shadowed by properties on the object in question - consider { hasOwnProperty: false } - or, the object may be a null object (Object.create(null)). In modern browsers Object.hasOwn can be used, which works for null objects and objects, where hasOwnProperty has been overridden.

    // bad
    console.log(object.hasOwnProperty(key));
    
    // good
    console.log(Object.prototype.hasOwnProperty.call(object, key));
    
    // better
    const has = Object.prototype.hasOwnProperty; // cache the lookup once, in module scope.
    console.log(has.call(object, key));
    // best
    console.log(object.hasOwn(key));
    /* or */
    import has from 'has'; // https://www.npmjs.com/package/has
    console.log(has(object, key));
    

There is also a rule for this available in eslint 8.5+ (https://eslint.org/docs/latest/rules/prefer-object-has-own).

Cheers

主要语言
JavaScript
星标
148k
派生
26.6k
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

airbnb/javascript 的其他 Issue

查看 airbnb/javascript 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。