Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Decorators Lightning Talk for Triangle JavaScript

333 views

Published on

A quick overview of the decorator proposal for JavaScript,

Published in: Software
  • Be the first to comment

Decorators Lightning Talk for Triangle JavaScript

  1. 1. @decorators Ben McCormick Windsor Circle Twitter: @ben336 Blog: http://benmccormick.org
  2. 2. Classes in JavaScript (History) • Prototypical inheritance • Variety of approaches
  3. 3. Lots of MVC Libraries Use Classes • Backbone • React • Ember • Angular
  4. 4. Backbone React Ember
  5. 5. ES6 Classes • Standard clean syntax • Fundamentally the same thing as older inheritance models • Browser support coming! (but use Babel for now)
  6. 6. Problems with ES6 Classes • You lose the flexibility of previous approach • No properties, just methods • Strict patterns for child classes
  7. 7. So how does this get better?
  8. 8. Proposed JavaScript Decorators
  9. 9. Decorators • Allow customization of classes and functions at class creation • Restore flexibility and expressiveness to class syntax • Similar to python decorators
  10. 10. Class Level Decorators
  11. 11. Method Decorators
  12. 12. Decorators are • Just functions • Take a class or method and act on it at creation time • Declarative! No messy code
  13. 13. Decorators Allow For • Cleaner interfaces • Class properties • Mixins
  14. 14. Cleaner Interface For Backbone
  15. 15.
  16. 16. https://github.com/benmccormick/backbone-decorators/ `on` decorator from
  17. 17. 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
  18. 18. Angular2 Aurelia
  19. 19. Next • ES2016 will get a draft by ~January • Released next June (possibly with decorators)
  20. 20. More info • https://github.com/wycats/ javascript-decorators • https://babeljs.io/docs/usage/ experimental/
  21. 21. Ben McCormick Windsor Circle Twitter: @ben336 Blog: http://benmccormick.org

×