0

I have a function declared like so;

+(function () { ... }());

Not my code, but I've been tasked with maintaining it, so knowing what's going on would be mighty handy. That's the only thing in the file, nothing else. JSHint complains with Expected an assignment or function call and instead saw an expression. and points to the )) as being the issue.

I've got a very basic understanding of why there's brackets around the function, although that understanding could definitely be improved. I don't know what the + is for. Nor do I know why JSHint is complaining. Maybe the two are related?

Trent
  • 1,595
  • 15
  • 37
  • 1
    The code is using two separate tricks to disambiguate the function expression; it just needs one. – Pointy Dec 21 '16 at 01:13
  • remove the `+` to remove the warning - some "linters" also prefer `(function () { ... })();` over `(function () { ... }());` – Jaromanda X Dec 21 '16 at 01:15
  • @JaromandaX ah yes, I have seen both styles in this code base. Could you maybe put down an answer to explain why the `+` is causing the error, I'd be happy to accept. – Trent Dec 21 '16 at 01:17

1 Answers1

1

Linters are quite finicky about which of the many styles to make IIFEs work to pick.

In your case you were using two approaches at once, drop the + and JShint should be happy.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375