箭头函数的使用
循环:for (let user of users)
数组方法的用法:https://www.cnblogs.com/sqh17/p/8529401.html
reduce的实现
Array.prototype.myReduce = function (calback, initialValue) {
const array = this
let acc = initialValue || array[0]
const startIndex = initialValue ? 0 : 1
for (let i = startIndex; i < array.length; i++) {
const cur = array[i]
acc = calback(acc, cur, i, array)
}
return acc
}
实现数组去重
// 数组去重
function MyUniq(array) {
let res = array.myReduce((acc, cur) => {
if (acc.indexOf(cur) < 0) {
acc.push(cur)
}
return acc;
}, [])
return res;
}
console.log(MyUniq([1, 1, 2, 3, 4, 2, 4, 7]))
模板字符串(反引号)的使用:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/template_strings
模板字符串使用反引号 (` `) 来代替普通字符串中的用双引号和单引号。模板字符串可以包含特定语法(${expression}
)的占位符。占位符中的表达式和周围的文本会一起传递给一个默认函数,该函数负责将所有的部分连接起来,如果一个模板字符串由表达式开头,则该字符串被称为带标签的模板字符串,该表达式通常是一个函数,它会在模板字符串处理后被调用,在输出最终结果前,你都可以通过该函数来对模板字符串进行操作处理。在模版字符串内使用反引号(`)时,需要在它前面加转义符(\)。
_updateTimeString(){
const comment=this.props.comment
const duration = (+Date.now()-comment.createdTime)/1000
this.setState({
timeString: duration > 60
? `${Math.round(duration / 60)} 分钟前`
: `${Math.round(Math.max(duration, 1))} 秒前`//这个符号```最左上角的
})
}