unicorn/prefer-reflect-apply 样式
作用
不允许使用 Function.prototype.apply(),并建议改用 Reflect.apply()。
为什么这不好?
Reflect.apply() 可以说更简洁,也更容易理解。 此外,当你接受任意方法时, 不能安全地假设 .apply() 一定存在或没有被重写。
示例
此规则的错误代码示例:
javascript
foo.apply(null, [42]);此规则的正确代码示例:
javascript
Reflect.apply(foo, null);如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/prefer-reflect-apply": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/prefer-reflect-apply": "error",
},
});bash
oxlint --deny unicorn/prefer-reflect-apply版本
此规则是在 v0.0.19 中添加的。
