从ES5到ES6(解决方案至代码挑战#13)

本文介绍了如何将ES5代码转换为ES6,包括使用箭头函数、增强的对象文字、对象解构、数组传播和模板文字等特性。通过实例解析,展示了这些ES6特性如何简化JavaScript编程并减少错误。
摘要由CSDN通过智能技术生成

Last week on the code challenge #13 we looked at converting sample code in ES5 to even simpler and more readable code in ES6. Yet to take the challenge? You can check it out here.

上周在代码挑战#13上,我们研究了将ES5中的示例代码转换为ES6中更简单,更易读的代码。 尚未接受挑战吗? 您可以在这里查看

In this post, we shall solve the challenge.

在这篇文章中,我们将解决挑战。

Awesome entries for the challenge can be found in the comment section of the post, on Twitter using the hashtag #ScotchChallenge and on the Spectrum forum.

您可以在帖子的评论部分,使用#ScotchChallenge的标签在Twitter上以及在Spectrum论坛上找到有关挑战的出色条目。

挑战 ( The Challenge )

No doubt that the ES6 version of JavaScript came with tons of amazing and useful features making web development with JavaScript even simpler and less error-prone.

毫无疑问,JavaScript的ES6版本具有大量令人惊奇且有用的功能,这些功能使使用JavaScript进行Web开发变得更加简单且不易出错。

In this challenge, we are presented with a set of 5 different code pieces requiring a re-write using a key ES6 feature. We would go over these individual challenges and the solution for each shortly. However, we were provided with boilerplate code written in ES5, we shall go over that briefly.

在这一挑战中,我们将看到一组5个不同的代码段,这些代码段需要使用关键的ES6功能进行重写。 我们将很快解决这些个人挑战和解决方案。 但是,我们提供了用ES5编写的样板代码,我们将简要介绍一下。

基地 ( The Base )

While no HTML and CSS is provided for this challenge, JavaScript is required and outputs from the script are logged to console. Each challenge is written in ES5 with a mix of ES5 and ES6 variable definitions.

尽管没有提供针对此挑战HTML和CSS,但需要JavaScript,并且脚本的输出会记录到控制台。 每个挑战都是用ES5编写的,混合了ES5和ES6变量定义。

Check out the codepen here: https://codepen.io/Chuloo/pen/xadjjO

在此处查看codepen: https ://codepen.io/Chuloo/pen/xadjjO

Looking at the script in the pen above, we can see the individual ES6 syntax requirements requested.

查看上面笔中的脚本,我们可以看到所请求的各个ES6语法要求。

技术 ( The Technique )

Going over each challenge we have:

克服我们遇到的每个挑战:

箭头功能 (Arrow Functions)

Arrow functions provide a simpler and better way to write functions, re-writing the first challenge we have:<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值