Loader vs ES6 Classes

Axel Rauschmayer axel at rauschma.de
Mon Aug 4 06:22:56 PDT 2014


A good point (independently of classes): why change the value of `this`?


On Aug 3, 2014, at 20:19 , John Barton <johnjbarton at google.com> wrote:

> Since I guess not too many developers work with ES6 and the Loader object, here is some feedback: the Loader callback design does not play well with ES6 classes.
> 
> The Loader takes 'options', an object with function properties like normalize, locate, and fetch. If you pass a literal object with function properties, it works fine.
> 
> If you pass an instance of a class, then you discover that the Loader calls these functions with 'this' bound to the Loader, not the 'options' object. 
> 
> There isn't a simple way around this as far as I know. The options functions don't have access to the options object, only module-state and global. So you're stuck with the awkward:
>    var loader = new Loader({
>       normalize: options.normalize.bind(options),
>       locate: options.locate.bind(locate),
>       etc,
>    };
> I guess you can give up on ES6 inheritance and create the hook instances by old-school JS, but that is even more annoying.  Or maybe there is something else I've not thought of?
> 
> jjb
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-- 
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140804/e28656d4/attachment.html>


More information about the es-discuss mailing list