Decorators vs Annotations (was April 10 2014 Meeting Notes)

Erik Arvidsson erik.arvidsson at gmail.com
Tue Apr 15 08:37:35 PDT 2014


On Tue Apr 15 2014 at 10:27:23 AM, Rick Waldron <waldron.rick at gmail.com>
wrote:

>
> ## Decorators for ES7
> (Yehuda Katz)
>
> Slides: (need slides)
>
> YK: Presenting aspects of common use cases not yet covered by ES6 `class`.
>
> Knockout.js example (compute the value of a property)
>
> WH: Do you want to use functors to produce functions that are per-class
> (i.e. on the prototype) or per-instance?
>
> AWB: Per instance wants to be handled in the constructor
>
> YUI example (a readonly property)
>
> LH/YK: Sometimes you want to say a method is readOnly
>
> AWB: No declarative way to describe the per instance state
>
> Angular example
>
> LH: (explanation) when I declare a class, I also want to register it with
> some other system
>
> ES6 Experiments: Angular
>
> ```js
> @NgDirective('[ng-bind]')
> class NgBind {
>   @Inject([Element])
>   constructor(element) {
>     this.element = element;
>   }
> }
> ```
>
> AWB: The "@" used to define an annotation
>
> JH: Point out that this is inert meta data
>

The main use case for Angular is for dependency injection. For that you
only need meta data.

Generally decorators are more powerful than annotations since decorators
can add the meta data as a side effect.

However, the main issue we ran into with decorators is annotating function
parameter:

```js
function doSomething(@inject xhr) {
  ...
}
```

With decorators it could course be rewritten as:
```js
@annotateParam(inject, 'xhr')
function doSomething(@inject xhr) {
  ...
}
```

Maybe that is sufficient? Maybe that could be done as syntactic sugar?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140415/63dd65ca/attachment.html>


More information about the es-discuss mailing list