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?
$.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.
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
subject: When to use $.fn.something = function() versus just function something()