no-new-symbol
禁止使用 Symbol 对象的 new 运算符
This rule was deprecated in ESLint v9.0.0. It will be removed in v11.0.0. Please replace the rule with no-new-native-nonconstructor.
Symbol 不是用于 new 运算符,而是作为函数调用。
var foo = new Symbol("foo");
这会抛出一个 TypeError 异常。
🌐 This throws a TypeError exception.
规则详情
🌐 Rule Details
这个规则旨在防止意外使用 new 运算符调用 Symbol。
🌐 This rule is aimed at preventing the accidental calling of Symbol with the new operator.
此规则的错误代码示例:
🌐 Examples of incorrect code for this rule:
/*eslint no-new-symbol: "error"*/
var foo = new Symbol('foo');
符合此规则的正确代码示例:
🌐 Examples of correct code for this rule:
/*eslint no-new-symbol: "error"*/
var foo = Symbol('foo');
// Ignores shadowed Symbol.
function bar(Symbol) {
const baz = new Symbol("baz");
}
何时不使用
🌐 When Not To Use It
此规则不应在 ES3/5 环境中使用。
🌐 This rule should not be used in ES3/5 environments.
由 TypeScript 处理
使用 TypeScript 时禁用此规则是安全的,因为 TypeScript 的编译器强制执行此检查。
版本
此规则是在 ESLint v2.0.0-beta.1 中引入。