0

How come, if I define jQuery.fn.my_method = function(){...}, jQuery.my_method is not undefined even though I put my_method under the .fn property and not under jQuery directly?

I'm just curious.

 <script>
     jQuery.fn.my_method = function(){...};
     jQuery.my_method();//valid call even though i put my_method under .fn
 </script>
Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
ionescho
  • 1,360
  • 2
  • 17
  • 31

1 Answers1

1

jQuery.fn is an alias for jQuery.prototype, just like how $ is an alias for jQuery. What you're describing is perfectly normal, you're adding a method to the prototype which then becomes available on the object.

I suggest reading up on JavaScript prototypes.

Community
  • 1
  • 1
Daniel Imms
  • 47,944
  • 19
  • 150
  • 166
  • Oh, i see... thanks. I know about prototypes that, if the program can't find a function directly under the object, it looks in its prototype. Also prototypes can only be defined on functions before instantiation . – ionescho Mar 25 '13 at 12:03