JavaScript语法foo是什么意思? [英] What does the JavaScript syntax foo: mean?

查看:3102
本文介绍了JavaScript语法foo是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码含义是什么? (它不是json - 它是不会由js解释器生成错误的代码)

what does the following code meaning? (it is not json - it is code which does not generate error by js interpreter)

foo: 5

问题的原因如下。在箭头函数示例中,有一个显示json和代码块语法之间的混淆:

The reason for the question is as follows. In the arrow function examples there is one that shows the confusion between json and code block syntax:

var func = () => { foo: 1 };

func()返回undefined,上面的代码不会失败。我试着把foo:5代码作为js模块中唯一的代码 - 它可以工作......我不知道':'运算符也不知道js中的标签。

The func() returns undefined and the above code does not fail. I tried to put just the foo: 5 code as the only code in a js module - and it works... I do not know about a ':' operator neither about labels in js.

推荐答案

这是一个JavaScript标签:这里的文档

It's a JavaScript label: documentation here.


您可以使用标签来标识循环,然后使用中断或者继续声明以指示程序是否应该中断循环或继续执行。

You can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.

注意JavaScript没有goto语句,你只能使用带有break或continue的标签。

Note that JavaScript has NO goto statement, you can only use labels with break or continue.

示例用法(来自MDN)

var itemsPassed = 0;
var i, j;

top:
for (i = 0; i < items.length; i++){
  for (j = 0; j < tests.length; j++) {
    if (!tests[j].pass(items[i])) {
      continue top;
    }
  }

  itemsPassed++;
}

这篇关于JavaScript语法foo是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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