Unknown JavaScript syntax before for…in

前端 未结 3 1344
慢半拍i
慢半拍i 2020-12-12 00:32

I am reading a book about single-page applications and at some point there is this for...in loop:

KEYVAL:
for(key_name in arg_map){
    if(arg_map.hasOwnProp         


        
相关标签:
3条回答
  • 2020-12-12 01:04

    It is for break and continue.

    Check the MDN

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

    0 讨论(0)
  • 2020-12-12 01:12

    KEYVAL: is a label here which is used in your loop for iteration the operations. Look at the documentation

    It is similar to GOTO statements.

    What it does in your code is when this condition become true

    if(key_name.indexOf('_') === 0) continue KEYVAL;
    

    its go to the label KEYVAL: and run the loop again without executing the code below this line.

    0 讨论(0)
  • 2020-12-12 01:12

    It is a label, sort of a line-number but not locked to a line position.

    Continue jumps to this label like a GOTO.

    When this criteria is furfilled:

    if(key_name.indexOf('_') === 0) continue KEYVAL;
    

    JavaScript continues from that label above.

    0 讨论(0)
提交回复
热议问题