Neither example binds 'this' assuming the current Loader implementation, so
no object state.  Although maybe you are saying your example ought to work,
then we agree ;-)


On Mon, Aug 4, 2014 at 7:47 AM, Axel Rauschmayer <a...@rauschma.de> wrote:

> On Aug 4, 2014, at 16:33 , John Barton <johnjbar...@google.com> wrote:
>
> As far as I can tell you are basically arguing that simple Loader hooks
> don't need object state. Of course that is true.
>
>
> No, I’m arguing that Juan’s code is basically “subclassing” a loader,
> overriding a method and calling that method. ES6 classes seem like a more
> elegant way of doing this. You’d get as much object state in the subclass
> as you want.
>
> And sure we can write code that carefully and cleverly avoids using
> 'this'. Why? ES6 added classes because this is often the clearest way to
> structure more complex systems.
>
> In my case the LoaderHooks.normalize() function needs to mark names as
> originating from 'script' rather than 'module' based on the name (eg
> 'script:' or in my case trailing ',script'.  The marking table needs to be
> on 'this'.
>
> I extend LoaderHooks to InterceptOuputLoaderHooks which calls
> this.onTranscoded() to copy the transcoded results from load to listeners.
>  But my real point is why should I have to think about 'this' binding in
> 2015?
>
> We don't need to use an old school API now, we have ES6.
>
> jjb
>
> On Mon, Aug 4, 2014 at 6:29 AM, Axel Rauschmayer <a...@rauschma.de> wrote:
>
>> On Aug 4, 2014, at 15:16 , Juan Ignacio Dopazo <jdop...@yahoo-inc.com>
>> wrote:
>>
>> In practice we've found that we rarely use the "new Loader(hooks)` option
>> and instead this is more common:
>>
>> var loader = new Loader();
>> var loaderFetch = loader.fetch.bind(loader);
>>
>> loader.fetch = function (loadRecord) {
>>   // do something
>>   return loaderFetch(loadRecord);
>> };
>>
>>
>>
>> Why not like this then? You’d need (a compiler for) ES6, though.
>>
>> ```js
>> class MyLoader extends Loader {
>>     fetch(loadRecord) {
>>         // do something
>>         return super(loadRecord);
>>     }
>> }
>> let loader = new MyLoader();
>> ```
>>
>
> --
> Dr. Axel Rauschmayer
> a...@rauschma.de
> rauschma.de
>
>
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to