Augustin Riedinger Augustin Riedinger - 9 days ago 5
Javascript Question

Get the list of custom jQuery plugin functions

I'd like to access the list of all possible functions accessible from a jQuery selector.

Say I created:

jQuery.fn.myPlugin = function() {};


I'd like to have the list of all those functions (including the native ones or not, depending on what's possible).

I expected
jQuery.fn
to work but it always returns a kind of empty array ...

> $.fn
[]


I can't believe I can't do that?

Thanks

Answer

Since jQuery doesn't use inheritance with fn and only uses enumerable properties on it, you can use Object.keys to get the full list:

var methods = Object.keys(jQuery.fn);

Of course, some plugin developer may have chosen to use defineProperty and make their plugin function non-enumerable; if so, we have to use Object.getOwnPropertyNames:

var methods = Object.getOwnPropertyNames(jQuery.fn);

I expected jQuery.fn to work but it always returns a kind of empty array ...

$.fn
[]

If you just want this information in the console, on Chrome that works; you just have to click the arrow next to the []:

enter image description here

to see the list

enter image description here