工具方法: jQuery.方法() $.extend (小计)

$.extend(布尔值,目标对象,合并对象,……)
                布尔值 : true,深拷贝(递归拷贝)   false,浅拷贝(非递归拷贝)
                
                对象方法:(给jQuery的prototype添加方法)
                $.fn.extend()

例子:

//             将字符串左边的空格去除
//             将字符串右边的空格去除
//             拓展到jQuery中
            
            $.extend({
                wipeLeftBlank : function(str){
                    let arr = str.split('');
                    for(var i = 0;arr[i] === ' ';){
                        arr.shift();
                    }
                    return arr.join("");
                    //return str.replace(/^s+/g,'');
                },
                wipeRightBlank : function(str){
                    let arr = str.split('');
                    for(var j = arr.length - 1;arr[j] === ' ';){
                        arr.pop();
                        j = arr.length - 1;
                    }
                    return arr.join("");
                    //return str.replace(/s+$/g,'');
                }
            })
            $.fn.extend({
                wipeLeftBlank : function(str){
                    let arr = str.split('');
                    for(var i = 0;arr[i] === ' ';){
                        arr.shift();
                    }
                    return arr.join("");
                    //return str.replace(/^s+/g,'');
                },
                wipeRightBlank : function(str){
                    let arr = str.split('');
                    for(var j = arr.length - 1;arr[j] === ' ';){
                        arr.pop();
                        j = arr.length - 1;
                    }
                    return arr.join("");
                    //return str.replace(/s+$/g,'');
                },
                drag : function(){
                    var that = this;
                    this.mousedown(function(evt){
                        // alert(this); //$('#box');
                        var disX = evt.pageX - $(this).offset().left;
                        var disY = evt.pageY - $(this).offset().top;
                        $(document).mousemove(function(evt){
                            //alert(this);  //原生节点对象
                            that.css({left : evt.pageX - disX,top : evt.pageY - disY});
                        })
                        $(document).mouseup(function(evt){
                            that.off();
                        })
                        return false;
                    })
                }
            })
            
            console.log('(' + $().wipeLeftBlank('    a    b    ') + ')');
            console.log('(' + $().wipeRightBlank('    a    b    ') + ')');
            $("#box").drag();
原文地址:https://www.cnblogs.com/lifeidg/p/10472627.html