Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

When to use $.fn.something = function() versus just function something()  RSS feed

 
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the subject says it all.

I was creating a function to use in my js files to do popups alerts, and I first tried with $.fn.showAlert = function(message). But then changed it to function showAlert(message).

So when should you use one over the other? benefits?

Thanks

Mark
 
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
$.fn is the jQuery prototype. You would create such a function when you want to extend jQuery and call the function as a method of the wrapped set. Within the function, the function context (this) refers to the wrapped set.

If that's not what you want to do, simply create a standalone function.
 
Mark Spritzler
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:$.fn is the jQuery prototype. You would create such a function when you want to extend jQuery and call the function as a method of the wrapped set. Within the function, the function context (this) refers to the wrapped set.

If that's not what you want to do, simply create a standalone function.



Great perfect, what I was thinking. So like a showAlert which isn't a function to act on a wrapped set, it should be function showAlert().

Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!