文档章节

ES6 new syntax features

Mercy_丶
 Mercy_丶
发布于 2016/05/24 15:54
字数 209
阅读 24
收藏 0
  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 example
var 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.name
console.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
    //usage
    
    var firstName = "Nate";
    var lastName = "Murray";
    // interpolate a string
    var greeting = `Hello ${firstName} ${lastName}`;
    console.log(greeting);
    
    
    var template = `
    <div>
    <h1>Hello</h1>
    <p>This is a great website</p>
    </div>
    `

     

© 著作权归作者所有

下一篇: JS基础知识
Mercy_丶
粉丝 8
博文 40
码字总数 16292
作品 0
私信 提问
js引入另外一个js

The old versions of JavaScript had no import, include, or require, so many different approaches to this problem have been developed. But recent versions of JavaScript have stand......

sd19871122
2017/12/01
0
0
3 Essential Sublime Text Plugins for Node & JavaSc

Check out these 3 great and essential Sublime Text plugins every JavaScript and Node developer should know about and use. JsFormat https://github.com/jdc0589/JsFormat JsFormat i......

cyper
2015/08/28
27
0
All About Angular 2.0

angular All About Angular 2.0Posted by Rob Eisenberg on November 6th, 2014. Have questions about the strategy for Angular 2.0? This is the place. In the following article I'll e......

Ethan_prog
2015/03/06
149
0
Bytom Blockchain/bytom-electron

Bytom Dashboard Development Setup Install Node.js: brew install node Install dependencies: npm install Start the development server with npm start By default, the development se......

Bytom Blockchain
2018/07/24
0
0
Visual Studio Code 1.22.0 和 1.22.1 发布,常规更新

Visual Studio Code 1.22.0 和 1.22.1 发布了。 1.22.0 更新内容 Syntax aware code folding - Adds improved folding for CSS, HTML, JSON, and Markdown files. Cross file error, warning......

达尔文
2018/04/07
2.3K
9

没有更多内容

加载失败,请刷新页面

加载更多

基于CentOS7搭建GitLab

基于CentOS7搭建GitLab 12018.11.02 16:38:51字数 959阅读 3791 本文作者:蓝雄威,叩丁狼高级讲师。原创文章,转载请注明出处。 一、简介 Git Lab GitLab是利用 Ruby on Rails 一个开源的版...

linjin200
26分钟前
6
0
random生成随机数

随机生成0到100之间的10个随机数,然后使用冒泡排序将这10个数按从小到大的顺序排序 生成10个随机数 import randomnum = range(0, 100) # 范围在0到100之间,需要用到range()函数。nums...

彩色泡泡糖
29分钟前
4
0
kubernetes 环境搭建 —— kubeadm

主从节点需要安装的服务 Master 节点 Node 节点 etcd-master Control plane(如:calico,fannel) kube-apiserver kube-proxy kube-controller-manager other apps kube-dns Control plane(如:......

lemos
32分钟前
4
0
php将字符串中的中英文数字分割

$str = "php如何将字 符串中322的字母数字Asf f45d和中文_分割?"; $arr = preg_split("/([a-zA-Z0-9]+)/", $str, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); print_r($arr); Arr......

小小小壮
33分钟前
3
0
茑屋书店理解(一)

说到实体书店,你可能会想到两个字“难做”。一是电子书大为盛行,二是纸书作为标准品,完全可以在网上购买,因此国内许多实体书店的日子是举步维艰。但是在日本有这么一家实体书店,目前已经...

Idea
36分钟前
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部