You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ECMAScript 5.1 specs allow calling Array(…) as a function, and the effect is the same as the new Array(…) constructor invocation. The same goes for other native constructors, e.g. Function. Currently, JSHint will issue a warning for this, though:
Missing 'new' prefix when invoking a constructor. (W064)
It would be nice if there were some option to control the behavior here: enforce constructor syntax, enforce function syntax, or allow mixing both. It would also be nice if we could include the name of the constructor in the message, so that one can easily distinguish between things which may be used as functions and things which may not be.
Looking at the current source, I see the check is implemented as
if ("Number String Boolean Date Object Error".indexOf(left.value) === -1)
This means that constructors which are substrings of the named native types will be subject to the same exceptions: a user-defined type called Num, Str, Bool or Obj would not trigger the error. I believe some proper set lookup would be preferable here. Or perhaps a regular expression matching all exceptions.
The text was updated successfully, but these errors were encountered:
The ECMAScript 5.1 specs allow calling
Array(…)
as a function, and the effect is the same as thenew Array(…)
constructor invocation. The same goes for other native constructors, e.g.Function
. Currently, JSHint will issue a warning for this, though:It would be nice if there were some option to control the behavior here: enforce constructor syntax, enforce function syntax, or allow mixing both. It would also be nice if we could include the name of the constructor in the message, so that one can easily distinguish between things which may be used as functions and things which may not be.
Looking at the current source, I see the check is implemented as
This means that constructors which are substrings of the named native types will be subject to the same exceptions: a user-defined type called
Num
,Str
,Bool
orObj
would not trigger the error. I believe some proper set lookup would be preferable here. Or perhaps a regular expression matching all exceptions.The text was updated successfully, but these errors were encountered: