eslint/no-obj-calls 正确性
作用
禁止将一些全局对象作为函数调用
为什么这不好?
一些全局对象并不打算作为函数被调用。将它们作为函数调用通常会导致抛出一个 TypeError。
示例
此规则的错误代码示例
javascript
let math = Math();
let newMath = new Math();
let json = JSON();
let newJson = new JSON();
let atomics = Atomics();
let newAtomics = new Atomics();
let intl = Intl();
let newIntl = new Intl();
let reflect = Reflect();
let newReflect = new Reflect();
此规则的正确代码示例
javascript
let area = (r) => 2 * Math.PI * r * r;
let object = JSON.parse("{}");
let first = Atomics.load(sharedArray, 0);
let segmenterFrom = Intl.Segmenter("fr", { granularity: "word" });