简体   繁体   中英

es6 arrow function doesn't work with switch statement

No error but I can't get my function triggered. Tried to put my exec_request function above or below the switch statement but still no luck.

exec_request = (url) => {
    alert('test') // not execute here?
}

switch(list_type) {
    case 'temp': {
        const url = `/shops/spaces/${temp}`;
        exec_request(url)
        break;
    }
    default: {
        const url = `/shops/${shop_id}/spaces`;
        exec_request(url)
    }
}

 const list_type = '';//'temp'; const temp = "tmp"; const shop_id = "123"; const exec_request = (url) => { alert(url) // not execute here? } switch(list_type) { case 'temp': { const url = `/shops/spaces/${temp}`; exec_request(url) break; } default: { const url = `/shops/${shop_id}/spaces`; exec_request(url) } } 

You probably need to call this.exec_request(url) .

Since you tagged this with and exec_request is not an global function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM