理解ECMAScript 6 模板字符串
理解ECMAScript 6 ,了解一些新的特性
1 字符串拼接方面
var myTooLongString = "A long time ago, in a galaxy far," +
"far away...." +
"It is a period of civil war." +
"Rebel spaceships, striking" +
"from a hidden base, have won" +
"their first victory against" +
"the evil Galactic Empire.";
var myTooLongString = `A long time ago, in a galaxy far far away.... It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire`;
2 字符串匹配
var items = [];
items.push("banana");
items.push("tomato");
items.push("light saber");
var total = 100.5;
result.innerHTML = `You have ${items.length} item(s) in your basket for a total of $${total}`;
总结
ie最新版本和chrome最新版本支持新的ECMAScript6 标准,如果你的目的是最新的浏览器可以尝试下新的技术
出处:http://www.noupe.com/development/understanding-ecmascript-6-template-strings-2-91959.html
每天一点点积累

浙公网安备 33010602011771号