Index

symbol-description

需要符号说明

Symbol 函数可能有一个可选的描述:

🌐 The Symbol function may have an optional description:

const foo = Symbol("some description");

const someString = "some description";
const bar = Symbol(someString);

使用 description 可以更容易调试:当一个符号被记录时,会使用其描述:

🌐 Using description promotes easier debugging: when a symbol is logged the description is used:

const foo = Symbol("some description");

> console.log(foo);
// Symbol(some description)

当在调试期间观察到符号时,它可能有助于识别符号。

🌐 It may facilitate identifying symbols when one is observed during debugging.

规则详情

🌐 Rule Details

此规则在创建符号时需要描述。

🌐 This rules requires a description when creating symbols.

此规则的错误代码示例:

🌐 Examples of incorrect code for this rule:

在线运行
/*eslint symbol-description: "error"*/

const foo = Symbol();

符合此规则的正确代码示例:

🌐 Examples of correct code for this rule:

在线运行
/*eslint symbol-description: "error"*/

const foo = Symbol("some description");

const someString = "some description";
const bar = Symbol(someString);

选项

🌐 Options

此规则没有选项。

🌐 This rule has no options.

何时不使用

🌐 When Not To Use It

这个规则不应该在 ES3/5 环境中使用。此外,如果你不想在创建 Symbol 时强制要求 description 的存在,可以安全地关闭此规则。

🌐 This rule should not be used in ES3/5 environments. In addition, this rule can be safely turned off if you don’t want to enforce presence of description when creating Symbols.

版本

此规则是在 ESLint v3.4.0 中引入。

进阶读物

资源