博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javascript 标签_JavaScript标签
阅读量:2520 次
发布时间:2019-05-11

本文共 1662 字,大约阅读时间需要 5 分钟。

javascript 标签

No matter how long you've been a JavaScript developer, there will always be language features that you didn't know about until you saw them in a fringe piece of code. Your reaction generally is a bit like:

不管您是一名JavaScript开发人员已有多久了,总会有一些您不了解的语言功能,直到您在一段附带的代码中看到它们为止。 您的React通常有点像:

Thinking

One of those features I see developers quizically trying to figure out is JavaScript labels, which allow you to manage break and continue with JavaScript loops. Let's have a look at them!

我看到开发人员奇怪地想找出的功能之一就是JavaScript标签,它允许您管理breakcontinue执行JavaScript循环。 让我们看看他们!

The basic format of a loop is {loopname}: before the loop starts:

循环的基本格式为{loopname}:循环开始前:

{loopName}:for({iterating}) {  {actions}}

The power of labels comes with nested loops -- you can use break and continue, paired with the label name, to manage loop escaping:

标签的功能带有嵌套循环-您可以使用breakcontinue (与标签名称配对)来管理循环转义:

function gogogo() {  firstLoop:  for (let outer = 0; outer < 4; outer++) {    secondLoop:    for (let inner = 0; inner < 5; inner++) {      if (inner === 3) {        // Use continue to avoid runs 4 and 5        continue firstLoop;      }      console.warn(`outer: ${outer}; inner: ${inner}`);    }  }}/*outer: 0; inner: 0outer: 0; inner: 1outer: 0; inner: 2outer: 1; inner: 0outer: 1; inner: 1outer: 1; inner: 2outer: 2; inner: 0outer: 2; inner: 1outer: 2; inner: 2outer: 3; inner: 0outer: 3; inner: 1outer: 3; inner: 2*/

Nested loops can be difficult to manage but labels make directing and escaping them easy. The next time you want to look like a smart one in the room, break out the JavaScript labels!

嵌套循环可能很难管理,但是标签使定向和转义变得容易。 下次您想在房间里看起来像个聪明人时,突破JavaScript标签!

翻译自:

javascript 标签

转载地址:http://nkvwd.baihongyu.com/

你可能感兴趣的文章
双系统开机引导菜单修复方法 进win7无须重启|metro引导|双系统菜单名字修改
查看>>
apache整合tomcat中的一些注意事项
查看>>
VC++使用Pro*CC++
查看>>
前端角度出发做好SEO需要考虑什么?
查看>>
laravel扩展图片处理Intervention Image
查看>>
【PDF】HTML中嵌入pdf的简单方法
查看>>
java集合系列——Map介绍(七)
查看>>
js导出表格
查看>>
Luogu P1550 [USACO08OCT]打井Watering Hole
查看>>
第7章 插件的使用和写法
查看>>
3283
查看>>
嘉为科技获得腾讯投资,拓展企业级IT运营管理市场
查看>>
java得到日期相减的天数
查看>>
安装denyhosts3.1版本报错如下
查看>>
12.1.2: How to Modify and Enable The Configurable Home Page Delivered Via 12.1.2 (Doc ID 1061482.1)
查看>>
Understanding Item Import and Debugging Problems with Item Import (Doc ID 268968.1)
查看>>
Alpha版总结会议
查看>>
Java--面试通关要点
查看>>
iOS 消息推送原理
查看>>
随笔1
查看>>