标签:ble foo table get 引号 调用 表达式 drs 入门
看了阮老师的ES6入门再加上自己的一些理解整理出的学习笔记
样子: `` 反引号,tab上面的那个键,同该符号包裹的字符串能够带来的功能如下:
$(‘#result‘).append( ‘There are <b>‘ + basket.count + ‘</b> ‘ + ‘items in your basket, ‘ + ‘<em>‘ + basket.onSale + ‘</em> are on sale!‘ );
$(‘#result‘).append(` There are <b>${basket.count}</b> items in your basket, <em>${basket.onSale}</em> are on sale! `);
$(‘#list‘).html(`
<ul>
<li>first</li>
<li>second</li>
</ul>
`);
${}
之中。(注:不声明会报错)let name = ‘jim‘, age = 18, gender = ‘male‘; console.log(`name : ${name} , age : ${age} , gender : ${gender}`)
let x = 1, y = 2; console.log(`${x} + ${y * 2} = ${x + y * 2}`)// "1 + 4 = 5"
let obj = {x: 1, y: 2}; console.log(`${obj.x + obj.y}`)// 3
function fn() { return "Hello World"; } console.log(`foo ${fn()} bar`)// foo Hello World bar
const tmpl = addrs => ` <table> ${addrs.map(addr => ` <tr><td>${addr.first}</td></tr> <tr><td>${addr.last}</td></tr> `).join(‘‘)} </table> `;
感谢观看!
最后安利阮老师的ES入门 : http://es6.ruanyifeng.com/#docs/string
标签:ble foo table get 引号 调用 表达式 drs 入门
原文地址:http://www.cnblogs.com/bfc0517/p/6700849.html