@decorators
Ben McCormick
Windsor Circle
Twitter: @ben336
Blog: http://benmccormick.org
Classes in JavaScript
(History)
• Prototypical inheritance
• Variety of approaches
Lots of MVC Libraries
Use Classes
• Backbone
• React
• Ember
• Angular
Backbone
React
Ember
ES6 Classes
• Standard clean syntax
• Fundamentally the same thing as
older inheritance models
• Browser support coming! (but use
Babel for now)
Problems with ES6
Classes
• You lose the flexibility of previous
approach
• No properties, just methods
• Strict patterns for child classes
So how does this get better?
Proposed JavaScript
Decorators
Decorators
• Allow customization of classes and
functions at class creation
• Restore flexibility and
expressiveness to class syntax
• Similar to python decorators
Class Level Decorators
Method Decorators
Decorators are
• Just functions
• Take a class or method and act on it
at creation time
• Declarative! No messy code
Decorators Allow For
• Cleaner interfaces
• Class properties
• Mixins
Cleaner Interface For
Backbone
…
https://github.com/benmccormick/backbone-decorators/
`on` decorator from
Current Status
• Proposed for inclusion in ES2016
(ES7)
• Already available in TypeScript
• Usable with Babel (experimental flag)
• Key part of Angular 2 and Aurelia
• Plans for using them for Ember/React
Angular2
Aurelia
Next
• ES2016 will get a draft by ~January
• Released next June (possibly with
decorators)
More info
• https://github.com/wycats/
javascript-decorators
• https://babeljs.io/docs/usage/
experimental/
Ben McCormick
Windsor Circle
Twitter: @ben336
Blog: http://benmccormick.org

Decorators Lightning Talk for Triangle JavaScript