no-obj-calls
注意: 此规则是
recommended
规则集的一部分。在
deno.json
中启用完整规则集{ "lint": { "tags": ["recommended"] } }
使用 Deno CLI 启用完整规则集
deno lint --tags=recommended
禁止像函数一样调用内置全局对象。
以下内置对象不应像函数一样调用,即使它们看起来像构造函数
Math
JSON
Reflect
Atomics
将这些作为函数调用会导致运行时错误。此规则静态地防止了这种错误用法。
无效
const math = Math();
const newMath = new Math();
const json = JSON();
const newJSON = new JSON();
const reflect = Reflect();
const newReflect = new Reflect();
const atomics = Atomics();
const newAtomics = new Atomics();
有效
const area = (radius: number): number => Math.PI * radius * radius;
const parsed = JSON.parse("{ foo: 42 }");
const x = Reflect.get({ x: 1, y: 2 }, "x");
const first = Atomics.load(foo, 0);