Today I learned

ES6 class pitfalls

This post was written in 2015.

class Shape {
  get area() {
    return this.width * this.height
  }
}

Decorated functions

ES6 makes it easy to define classes, but you can't have decorated functions. For that, you'll still need to drop to using prototype.

Shape.prototype.iterate = memoize(function () {
  ...
})

Non-method attributes

Same with non-method attributes.

Shape.prototype.template = require('fs').readFileSync(
  './template.html',
  'utf-8'
)

You have just read ES6 class pitfalls, written on February 25, 2015. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles