current position:Home>Write jQuery plug-in sharing

Write jQuery plug-in sharing

2021-08-22 05:30:27 mb611f1a641bd18

One 、 Class level ($.extend)

     Class level you can understand as extension jquery class , The most obvious example is $.ajax(...), Equivalent to a static method .

    When developing methods to extend it, use $.extend Method , namely jQuery.extend(object);

 To write jquery Plug in sharing

 

Two 、 Object level

Object level can be understood as object-based extension , Such as $("#table").changeColor(...); Here it is. changeColor Well , It's object-based expansion .

When developing methods to extend it, use $.fn.extend Method , namely jQuery.fn.extend(object);

 To write jquery Plug in sharing

3、 ... and 、 jQuery Plug in development process

 1、 Define scope : Define private scopes for plug-ins , External code cannot directly access the internal code of the plug-in , Code inside plug-ins does not pollute global variables 、

 To write jquery Plug in sharing

 2、 by jQuery Extend a plug-in : by jQuery Add a spread method to the instance of . The spread method can receive some parameters .

 To write jquery Plug in sharing

3、 Set the default value : Set default values for extension methods , Generally, the default attribute object is defined as defaults. Use $.extend(defaults,options) Merge the default value with the passed in parameter

 To write jquery Plug in sharing

4、 Support jQuery Connection call for : Loop returns each element to .

 To write jquery Plug in sharing

5、 Methods in plug-ins : To visualize the structure of the code , Need to use function. Methods in plug-ins cannot be called by outsiders

 To write jquery Plug in sharing

6、 Custom callback functions : Use call and apply Method to execute the callback function ,

 To write jquery Plug in sharing

notes : Reproduced in http://jingyan.baidu.com/article/e75aca85550216142edac63b.html

copyright notice
author[mb611f1a641bd18],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210822053023910Q.html

Random recommended