In the previous section we have used $.fn.myplugin to extend a method to jquery, while also ensuring that the chained invocation of jquery has not been compromised. The attentive little companions may have noticed that in the $.fn.myplugin method we used the constructor to generate an object, as follows:
In fact, we really implement our own plug-in code is written in the Myplugin constructor, so the benefit is that when we use the $ (selector). Myplugin (Options), the following actions are performed:
(1) Select the current element and read the Myplugin attribute under the current element;
(2) Determine whether the attribute book exists, if there is a step (4), if there is no step (3);
(3) When there is no myplugin attribute under the element, instantiate a Myplugin object and save the object under the selected element;
(4) Determine the parameters of the Myplugin, if it is a string type, then invoke the method under the instance.
jquery Plugin pre-development preparation (II)