JS笔记:ES6 Syntactical Sugar

2017-08-05  本文已影响8人  开水的杯子

Templating

Basically you can use the same syntax as groovy string interpolation.

// Multiline strings
`This is a legal
string in ES 6.`

// String interpolation
var name = "Bob", time = "today";
`Hello ${name}, how are you ${time}?`

Variable Arguments

Vanilla JS arguments array

function foo() {
  console.log(arguments);
}

foo(1, 2, 3); // [1, 2, 3]

ES6 Rest Parameters

function foo(a, b, ...theArgs) {
  // ...
}

ES6 Default Parameters

function foo(x=12) {
  console.log(x);
}

foo(); // 12
foo(1); // 1
上一篇 下一篇

猜你喜欢

热点阅读