Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calling Array as a function #1987

Closed
gagern opened this issue Nov 18, 2014 · 0 comments
Closed

Allow calling Array as a function #1987

gagern opened this issue Nov 18, 2014 · 0 comments

Comments

@gagern
Copy link

gagern commented Nov 18, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant