Skip to content Skip to sidebar Skip to footer

Assigning Dependencies In Controllers Using The Es6 Class Syntax

In a video from ng-conf 2015 (Angular 1.3 meets Angular 2.0), the syntax for using ES6 classes as controllers is shown as: class UnicornHype { constructor(unicornHorn, $q) {

Solution 1:

I don't really understand why they use Weakmaps. I quote:

Reason behind choosing WeakMap is, the entries of WeakMap that have objects as keys are removed once the object is garbage collected.

But aren't services long-lived? So why would you need to ensure garbage collection?

In javascript all non-primitives are pointers to the original instance, so the dependencies are always shared. So why would the instance-variable approach not be a good idea?

Anyway, I think the instance-variable approach seems the most future-proof way to go.

Post a Comment for "Assigning Dependencies In Controllers Using The Es6 Class Syntax"