SOURCE

function get(path, params) {
    console.log('get', path, params)
}
function post(path, params) {
    console.log('post', path, params)
}
function fetchApi(type, path, params) {
    switch (type) {
        case 'get': return get(path, params)
        case 'post': return post(path, params)
    }
}
function user() {
    let useApiUrlMap = {
        getUserInfo: 'https:// getuserInfoURl',
        setUserInfo: 'https:// setUserInfo'
    }
    return {
        getUserInfo: function (params) {
            fetchApi('get', useApiUrlMap['getUserInfo'], params)
        },
        setUserInfo: function (params) {
            fetchApi('get', useApiUrlMap['setUserInfo'], params)
        }
    }
}

function goods() {
    let useApiUrlMap = {
        getGoodsInfo: 'https:// getGoodsInfoUrl',
        setGoodsInfo: 'https:// setGoodsInfo'
    }
    return {
        getGoodsInfo: function (params) {
            fetchApi('get', useApiUrlMap['getGoodsInfo'], { data: 4 })
        },
        setGoodsInfo: function (params) {
            fetchApi('get', useApiUrlMap['setGoodsInfo'], { data: 5 })
        }
    }
}

function requeest(type) {
    let apiTypsMap = {
        user,
        goods
    }
    return apiTypsMap[type] && apiTypsMap[type]()
}

let userReq = new requeest('user')
userReq.getUserInfo({tt: 4})   // > get,https:// getuserInfoURl,{"tt":4}
let goodsReq = new requeest('goods')
goodsReq.getGoodsInfo()   // > get,https:// getGoodsInfoUrl,{"data":4}
console 命令行工具 X clear

                    
>
console