deno.com

no-prototype-builtins

注意: 此规则是 recommended 规则集的一部分。
deno.json 中启用完整规则集:
{
  "lint": {
    "rules": {
      "tags": ["recommended"]
    }
  }
}
使用 Deno CLI 启用完整规则集:
deno lint --rules-tags=recommended

禁止直接使用 Object.prototype 内置方法。

如果对象是通过 Object.create(null) 创建的,它们没有指定的原型。当你假设对象具有 Object.prototype 的属性并尝试调用以下方法时,这可能会导致运行时错误:

  • hasOwnProperty
  • isPrototypeOf
  • propertyIsEnumerable

相反,始终鼓励从 Object.prototype 显式调用这些方法。

无效:

const a = foo.hasOwnProperty("bar");
const b = foo.isPrototypeOf("bar");
const c = foo.propertyIsEnumerable("bar");

有效:

const a = Object.prototype.hasOwnProperty.call(foo, "bar");
const b = Object.prototype.isPrototypeOf.call(foo, "bar");
const c = Object.prototype.propertyIsEnumerable.call(foo, "bar");

你找到需要的内容了吗?

隐私政策