ES6新特性
模板对象 in ES6
ES5中我们使用字符拼接方式组合一个字符串
var name = 'Your name is' + firstName + '' + lastName +'.'
var url='http://localhost:3000/api/message/'+ id;
ES6中,我们可以使用新的语法${NAME},并把它放在反引号里:
var name = `Your name is ${first}${last}.`
var url=`http://localhost:3000/api/messages${id}.`
多行字符串 in ES6
ES5:
var roadPoem = 'Then took the other, as just as fair,nt'
+ 'And having perhaps the better claimnt'
+ 'Because it was grassy and wanted wear,nt'
+ 'Though as for that the passing therent'
+ 'Had worn them really about the same,nt';
var fourAgreements = 'You have the right to be you.n
You can only be you when you do your best.';
ES6:
var roadPoem = `Then took the other, as just as fair,
And having perhaps the better claim
Because it was grassy and wanted wear,
Though as for that the passing there
Had worn them really about the same,`;
var fourAgreements = `You have the right to be you.
You can only be you when you do your best.`;