Javascript Standardjs - How To Fix 'is Already Defined'?
What is the better to fix this 'error' of 'is already defined'? function findOneAndUpdate (find) { var find = find || {} ... } The test from standardjs: $ standard ... '
Solution 1:
ES6+ solution with default parameters:
functionfindOneAndUpdate(find={}) { ... }
ES5- would be renaming:
functionfindOneAndUpdate(_find) {
var find = _find || {}
...
}
Otherwise, you can completely replace the variable, like other answers suggest:
functionfindOneAndUpdate(find) {
find = find || {}
...
}
Solution 2:
You need to leave out the var
, because the variable find
is already declared through the method header:
functionfindOneAndUpdate(find) {
find = find || {};
...
}
Solution 3:
Why not just change either the function parameter name or the new variable's name?
The variable name find
is clashing with the parameter find
.
If all you want is give it an empty object as default parameter, you can safely reuse the parameter:
find = find || {}
, just remove the var
.
Post a Comment for "Javascript Standardjs - How To Fix 'is Already Defined'?"