Skip to content

Instantly share code, notes, and snippets.

@amio
Last active August 29, 2015 14:27
Show Gist options
  • Save amio/4336a61939691164ba0d to your computer and use it in GitHub Desktop.
Save amio/4336a61939691164ba0d to your computer and use it in GitHub Desktop.
ES6 Tricks

ES6 Tricks

整理一些用 ES6 书写会格外高效的代码,也是对 ES6 语法的练习。

Professional log

用法:

// 普通 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:(此处略去五百字)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment