1.变量声明-let 与 const
2.模版字符串
使用 反引号``(键盘上esc下面那个键) 将整个字符串包裹起来,而在其中使用 ${} 来包裹一个变量或者一个表达式
3.拓展运算符 (展开运算符)
在ES6中用...
来表示展开运算符,它可以将数组方法或者对象进行展开。上栗子
//1.函数调用中使用展开运算符
function test(a, b, c) { } var args = [0, 1, 2]; test.apply(null, args); 在ES6里可以这样写 function test(a,b,c) { } var args = [0,1,2]; test(...args);
//2.数组字面量中使用展开运算符
const arr1 = [1, 2, 3]; const arr2 = [...arr1, 10, 20, 30]; // 这样,arr2 就变成了[1, 2, 3, 10, 20, 30];
4.箭头函数
函数的快捷写法,不需要通过 function
关键字创建函数,并且还可以省略 return
关键字。(注意:箭头函数本身没有this,如果在箭头函数内使用this,这个this一定是它上级的this,再有就是箭头函数可以代替函数表达式,但代替不了函数声明,它还是需要声明才能使用的)。
var person = { name: 'tom', getName: function() { return this.name; } } // 用ES6的写法来重构上面的对象 const person = { name: 'tom', getName: () => this.name } // 但是编译结果却是 var person = { name: 'tom', getName: function getName() { return undefined.name; } };