JSlint doesn't like the use of Array constructors and there are no JSLint options for allowing them. Therefore, to create an Array of length n, the following is not allowed:
var arr = new Array(n);
Is the below the only way I can get around this?
var arr = [];
arr.length = 5;
In normal circumstances this is not a big deal (using two lines of code instead of one), but I regret not being able to use the concise string multiplier hack:
function repeat(str, times) {
return new Array(times + 1).join(str);
}
JSLint is fairly easy to outsmart.
You can just do this:
function repeat(str, times) {
var A = Array;
return new A(times + 1).join(str);
}
This would also work:
function repeat(str, times) {
return new Array.prototype.constructor(times + 1).join(str);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With