Reputation: 1400
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>
Upvotes: 0
Views: 37
Reputation: 50149
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.
Upvotes: 1