整理一些用 ES6 书写会格外高效的代码,也是对 ES6 语法的练习。
用法:
// 普通 log
log('UI updated.') // ==> 'UI updated.'
log('Shit happens.') // ==> 'Shit happens.'
// 文艺 log
fetchData()
.then(/* do something */)
.catch(log('About Page:')) // ==> About Page: Error 404.
// 逗比 log
log('Thunk')('you')('for')('watching')('...')
ES6:
function log (...args) {
console.log.apply(console, args)
return (...more) => log(...args.concat(more))
}
ES5:(此处略去五百字)