for ... in之前的JavaScript语法未知 [英] Unknown JavaScript syntax before for...in

查看:186
本文介绍了for ... in之前的JavaScript语法未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一本关于单页应用程序的书,并且在某些时候有这样的...循环:

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.hasOwnProperty(key_name)){
        if(key_name.indexOf('_') === 0) continue KEYVAL;

        anchor_map_revise[key_name] = arg_map[key_name];

        key_name_dep = '_' + key_name;
        if(arg_map[key_name_dep]){
            anchor_map_revise[key_name_dep] = arg_map[key_name_dep];
        }
        else{
            delete anchor_map_revise[key_name_dep];
            delete anchor_map_revise['_s' + key_name_dep];
        }
    }
}

真正引起我注意的是循环之前的 KEYVAL 字。它是变量吗?它代表什么?它是为了什么?这个语法是什么意思?这个词只出现在所包含的代码中的两个地方,并且在整个例子中都没有出现过。

What really caught my eye was the KEYVAL word right before the loop. Is it a variable? What does it represent? What is it for? What does this syntax mean? The word only appears in the two places in the included code and never again in the whole example.

我一直在寻找很多东西,但是所以到目前为止,我还没有找到任何信息。有人可以帮帮我吗?

I've been searching a lot trying to figure this out, but so far I have not been able to find any information. Could someone please help me out?

谢谢。

推荐答案

KEYVAL:是一个标签,在循环中用于迭代操作。查看文档

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

它类似于GOTO语句。

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;

转到标签 KEYVAL:和再次运行循环而不执行此行下面的代码。

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

这篇关于for ... in之前的JavaScript语法未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆