EDIT: based on the provided links.
The reason your secondAPI method secondAPI not work is because $.fn.myPlugin is a Function object that inherits from this prototype chain. To create an instance of an object that inherits from the prototype of $.fn.myPlugin , you need to use the new operator to create a new $.fn.myPlugin .
It looks like the method you are using is based on jQuery factory widgets. Look at the source for the jQuery UI Widget (specifically the $.widget method), and then at the source of something that uses the jQuery UI factory widget.
First, Widget takes as its second argument the constructor for the object you want to extend. Inside, it then creates an object of this type using the new operator, and then extends this object using the method you showed. After that, it creates your plugin logic using the $.widget.bridge method so that you can use the plugin in the usual way, i.e. $(element).myPlugin(); . Then you can call any functions using $(element).myPlugin("apiMethod");
I suggest you read the source and the documentation to understand what is going on. Then it might be a good idea to use Widget Factory for your own plugins. This is really great work and will save you a lot of effort in coding part of the extension of your own plugins.
source share