jslint
jslint copied to clipboard
Allow detect when function argument shadows existing variable
In the following code I use variable "s" to store string "foo", then I want to iterate over "data" array using forEach, I use function argument "s" which "overwrites" the parent "s". Jslint currently does not show it as warning:
var s = "foo";
var data = [1, 2, 3];
data.forEach(function (s) {
console.log(s, "long text so you don't notice arg s shadowed parent s", s);
});
Could jslint produce warning, something like:
Redefinition of 's' from line 1.
JSLINT already does it for local variables:
var s = "foo";
var data = [1, 2, 3];
function foo() {
var s = "asdf"; // JSLINT warning: Redefinition of 's' from line 1.
console.log(s);
}