博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ES6 new syntax features
阅读量:7116 次
发布时间:2019-06-28

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

hot3.png

  1.  Fat arrow function syntax
  •  fat arrow 即:  '=>'   
  • 通常我们在调用一个方法里带有一个function作为参数时我们一般这样用:
var data = ['Alice Green', 'Paul Pfifer', 'Louis Blakenship'];data.forEach(function(line) { console.log(line); });
  •  现在我们可以使用这种 fat arrow "=>" ,于是上面科一这样写:
// Typescript examplevar data: string[] = ['Alice Green', 'Paul Pfifer', 'Louis Blakenship'];data.forEach( (line) => console.log(line) );
  •  另一个 => 的特性就是 他可以为其上文的代码公用一个  this ,例如:
/***********ES5**************/var nate = {name: "Nate",guitars: ["Gibson", "Martin", "Taylor"],printGuitars: function() {var self = this;this.guitars.forEach(function(g) {// this.name is undefined so we have to use self.nameconsole.log(self.name + " plays a " + g);});}};/***********ES6**************/var nate = {name: "Nate",guitars: ["Gibson", "Martin", "Taylor"],printGuitars: function() {this.guitars.forEach( (g) => {console.log(this.name + " plays a " + g);});}};

         2、Template Strings

  • Variables within strings (without being forced to concatenate with + ) and
  • Multi-line strings
    //usagevar firstName = "Nate";var lastName = "Murray";// interpolate a stringvar greeting = `Hello ${firstName} ${lastName}`;console.log(greeting);var template = `

    Hello

    This is a great website

    `

     

转载于:https://my.oschina.net/mercyyang/blog/680527

你可能感兴趣的文章
VINS(七)estimator_node 数据对齐 imu预积分 vision
查看>>
pku1274 The Perfect Stall
查看>>
android开发之图表
查看>>
redis实现分布式锁工具类 灰常好用
查看>>
rocketmq Don't have SubscriptionGroup
查看>>
Arx 函数
查看>>
verilog语法实例学习(13)
查看>>
iOS/oc取消arc[转]
查看>>
关于硅谷的文化
查看>>
注册表单验证
查看>>
except ShortInputException,x中逗号
查看>>
Yii快速入门教程
查看>>
xshell与虚拟机对接
查看>>
关于网站编程Alex
查看>>
leetcode-804-Unique Morse Code Words
查看>>
Angular企业级开发(3)-Angular MVC实现
查看>>
递归大总结之位运算实现加法
查看>>
filter()和map()
查看>>
如何快速阅读源码
查看>>
磁盘扩容
查看>>