0

When creating a function and immediately calling it afterward, is there a difference in these two implementations?

(function ($) {
     ....some code....
}(jQuery))

or

(function ($) {
     ....some code....
})(jQuery)

Which is the correct method to use?

user5013
  • 981
  • 4
  • 10
  • 21
  • 12
    No difference and this is a duplicate a zillion times over :) – Pointy Oct 15 '13 at 20:00
  • @user5013 Do YOU see any difference ? – karthikr Oct 15 '13 at 20:02
  • The only reason why the brackets are needed is to differentiate between a function declaration(which can't be invoked) and a function expression(which yields a function value, and thus, can be invoked). – Sacho Oct 15 '13 at 20:02
  • 1
    There is no difference. Here you can see some more explanations - http://stackoverflow.com/questions/9734055/what-is-the-difference-between-these-2-javascript-declarations – Misha Zaslavsky Oct 15 '13 at 20:03
  • i prefer the first one, nobody wants to look at your un-sheathed dog balls. – dandavis Oct 15 '13 at 20:06
  • Thanks for the link to the similiar question. I didn't find it when I first searched for it (probably used the wrong terms). – user5013 Oct 15 '13 at 20:07
  • jslint favours the first one, though there's no real difference. – David Barker Oct 15 '13 at 20:49

0 Answers0