What is the difference between $.myfunc and $.fn.myfunc? I can see one needs return value and use $().myfunc() to invoke while the other one is not. Can the community suggest me some reference or keywords to get more understanding? Thanks.
What is the difference between $.myfunc and $.fn.myfunc? I can see one needs return
Share
$.myfunc refers to a “static” or global function in the jquery namespace. It is not reliant on jquery initialisation via a selector such as $(‘#id’).myfunc(…).
$.ajax is an example.
$.fn.myfunc on the other hand adds myfunc to the prototype of the jquery object, so that when a jquery objetc is created via a selector $(‘#id’) the new object has a method called myfunc that is invokable in the context of the newly created jquery object.