Stuff to mind when writing ES6 code

These are some good tips I picked up browsing the ember and commits. Nice if you're looking for best practices in writing ES6 code.

example: diverging bindings

this is an issue when dealing with cycles.

bad: (diverges bindings)

import { foo } from 'bar';

var otherFoo = foo;
foo: (if the rename is actually needed)


import { foo as otherFoo } from 'bar';

example: closure compiler dead code remove friendly:

bad: closure compile wont drop, bar if foo is used, or foo if bar is used

export default {
  foo: function() { },
  bar: function() { }

good: closure compile will drop whats not used correctly.

export function foo() { }
export function bar() { }

Some other interesting tidbits (not sure of the validity of all of these, but this is what some of the Ember guys claim):

  • re-using argument variables makes it quite hard to see the original value
  • re-using argument variables has some negative performance side-effects.
  • using the comma operator for long variable declarations makes it impossible to easily set breakpoints.