File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic