(function ($) {
    // $.extend,JQ扩展，添加JQ的静态方法，与具体JQ对象无关
    $.extend({
        userPlugin: {
            ParseIntData: (data) => {
                switch (typeof data) {
                    case "string":
                        return $.userPlugin.ParseIntString(data)
                    case "object":
                        if (data.length === undefined) {
                            return $.userPlugin.ParseIntObj(data)
                        }

                        return $.userPlugin.ParseIntArr(data)
                    default:
                        return data
                }
            },
            ParseIntArr: (arr) => {
                let intArr = []
                for (const k in arr) {
                    const v = arr[k]
                    switch (typeof v) {
                        case "object":
                            intArr.push($.userPlugin.ParseIntObj(v))
                            break;
                        case "string":
                            intArr.push($.userPlugin.ParseIntString(v))
                            break;
                        default:
                            intArr.push(v)
                            break;
                    }
                }
                return intArr
            },
            ParseIntObj: (obj) => {
                let intObj = {};
                $.each(obj, (k, v) => {
                    switch (typeof v) {
                        case "string":
                            intObj[k] = $.userPlugin.ParseIntString(v)
                            break;
                        case "object":
                            intObj[k] = $.userPlugin.ParseIntObj(v)
                            break;
                        default:
                            intObj[k] = v
                            break;
                    }
                })

                return intObj
            },
            ParseIntString: (string) => {
                const intV = parseInt(string)
                return isNaN(intV) ? string : intV
            }
        }
    })


    // $.fn.extend，添加JQ实例对象的方法扩展，$("#A1")它代表一个JQ对象
    $.fn.extend({
        serializeObject: function () {
            const obj = {};
            const arr = this.serializeArray();
            arr.forEach(v => {
                if (obj[v.name] !== undefined) {
                    if (!obj[v.name].push) {
                        obj[v.name] = [obj[v.name]];
                    }
                    obj[v.name].push(v.value || '');
                } else {
                    obj[v.name] = v.value || '';
                }
            })

            return obj;
        }
    })

}(jQuery));
