Are there legitimate uses for JavaScript's “with” statement?

后端 未结 30 1773
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 04:22

Alan Storm\'s comments in response to my answer regarding the with statement got me thinking. I\'ve seldom found a reason to use this particular language feature, and had ne

30条回答
  •  醉话见心
    2020-11-22 05:29

    My

    switch(e.type) {
        case gapi.drive.realtime.ErrorType.TOKEN_REFRESH_REQUIRED: blah
        case gapi.drive.realtime.ErrorType.CLIENT_ERROR: blah
        case gapi.drive.realtime.ErrorType.NOT_FOUND: blah
    }
    

    boils down to

    with(gapi.drive.realtime.ErrorType) {switch(e.type) {
        case TOKEN_REFRESH_REQUIRED: blah
        case CLIENT_ERROR: blah
        case NOT_FOUND: blah
    }}
    

    Can you trust so low-quality code? No, we see that it was made absolutely unreadable. This example undeniably proves that there is no need for with-statement, if I am taking readability right ;)

提交回复
热议问题