索引
const person=‘Jelly‘;
const age=20;
const intro=`${person} is ${age} years old`;
const html=`
<div class="greet">
<p>hello</p>
</div>
`.trim()
const Jelly={
name:‘Jelly‘,
date:‘2020-02-10‘,
todos:[
{name:‘sleep in bed‘,completed:false},
{name:‘music‘,completed:true},
{name:‘water‘,completed:false}
]
}
function renderTodos(todos) {
const str=
`<ul>
${todos.map(todo =>
`
<li>
${todo.name} ${todo.completed ? ‘1‘ : ‘0‘}
</li>
`).join(‘‘)
}
</ul>
`
return (str)
}
const tpl=`
<div class="panel">
<div class="panel-header">${Jelly.name}</div>
<div class="panel-body">
${renderTodos(Jelly.todos)}
</div>
<div class="panel-footer">${Jelly.date}</div>
</div>
`
const user=‘marry‘
const topic="learn to use Markdown"
const sentence=highlight`${user} has commented on your topic ${topic}`
function highlight(strings,...values){
debugger
}
strings与values
Local
strings: (3) ["", " has commented on your topic ", "", raw: Array(3)]
values: (2) ["marry", "learn to use Markdown"]
this: Window
const user=‘marry‘
const topic="learn to use Markdown"
const sentence=highlight`${user} has commented on your topic ${topic}`
function highlight(strings,...values){
const highlighted=values.map(value =>
`<span class="highlight">${value}</span>`
)
let str=‘‘;
strings.forEach((string,i)=>
str+=`${string}${highlighted[i]||‘‘}`
)
return str
}
进化html里输入的脚本:sanitize
原文:https://www.cnblogs.com/HKUI/p/13112106.html