no-new-func
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-new-func": "error",
},
},
];const a = new Function("a", "b", "return a + b");
const b = Function("a", "b", "return a + b");
const c = Function.call(null, "a", "b", "return a + b");
const d = Function.apply(null, ["a", "b", "return a + b"]);
const x = Function.bind(null, "a", "b", "return a + b")();
const y = Function.bind(null, "a", "b", "return a + b"); // assuming that the result of Function.bind(...) will be eventually called.const x = function (a, b) {
return a + b;
};Examples from the ESLint documentation.
no-new-func
eslint
export default [
{
rules: {
"no-new-func": "error",
},
},
];no-new-func
eslint plugin · style
{
"rules": {
"no-new-func": "error"
}
}nursery/noImpliedEval
nursery · since 2.4.10
{
"linter": {
"rules": {
"nursery": {
"noImpliedEval": "error"
}
}
}
}Disallow unnecessary calls to .bind()
Disallow new operators with the String, Number, and Boolean objects
Disallow throwing literals as exceptions
Disallow unnecessary computed property keys in objects and classes