no-obj-calls
NOTE: this rule is part of the
推荐
rule set.Enable full set in
deno.json
:{ "lint": { "rules": { "tags": ["推荐"] } } }
Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include
or exclude
array in deno.json
:{ "lint": { "rules": { "include": ["no-obj-calls"], "exclude": ["no-obj-calls"] } } }
禁止像函数一样调用内置全局对象。
以下内置对象即使看起来像构造函数,也不应该被当作函数调用:
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);