ES6参数默认值

版权声明:未经本人同意不得私自转载 https://blog.csdn.net/qq_40190624/article/details/82715451

方式一:

function makeAjaxRequest(url,method){
    if(!method){//在METHOD没有值的情况下为GET
        method = "GET";
    }
    return method;//GET
}

方式二:\

function makeAjaxRequest(url,method = "get"){
    
    return method;//post,在没传值的情况下为get,
}
console.log(makeAjaxRequest('google.com'));
console.log(makeAjaxRequest('google.com',"POST"));

猜你喜欢

转载自blog.csdn.net/qq_40190624/article/details/82715451
今日推荐