On Thu, May 31, 2012 at 7:01 PM, Mark S. Miller <[email protected]> wrote:
snip

>  // Imaginary DOM library
>> DOM = {};
>>
>> // This function accepts a function as it's second argument,
>> // what happens when its a bound function? I'd like write the
>> // API in a way that is friendly to both types of function
>>
>> DOM.each = function( elems, callbackFn ) {
>>   var bound;
>>
>>   // I made this up, but it makes sense because fat arrows don't
>>   // have a prototype, so Function.prototype.isBound() is out
>>
>
>  fat arrow functions don't have a ".prototype" but they do have a
> [[Prototype]] of Function.prototype, and so would still inherit
> Function.prototype.isBound() as an instance method. No matter, I don't
> really care what the predicate is named, which way the truth value goes, or
> how it is invoked. So far, this example is fine.
>

Wouldn't this mean that fat arrow functions inherit call, apply and bind as
well? (I may have misunderstood this aspect)


>
>>   //
>>   if ( !Function.isBound(callbackFn) ) {
>>     // When not explicitly bound,
>>     // DOM.each sets |this| to the object being iterated
>>     bound = callbackFn.bind( elems );
>>   }
>>
>
> I don't understand. Here, you're conditionally assigning the newly bound
> function bound to the "bound" variable. But then you're not using the
> "bound" variable anywhere. Binding itself has no side effect, so this code
> seems like a noop. Typo?
>

Yes, sorry, that is a typo - I put this example together quickly, I
should've reviewed it a little more thoroughly. Sorry for the confusion.

Rick


>
>
>
>>   [].forEach.call( elems, callbackFn );
>> }
>>
>> let nodes = document.querySelectorAll(".theclass");
>>
>> DOM.each( nodes, function( index ) {
>>   // the node is at: this[ index ]
>> });
>>
>>
>> function ListOfNodes( selector ) {
>>   let nodes = document.querySelectorAll( selector );
>>
>>   // I don't want to return a NodeList, I'm
>>   // making my own API - WOO!
>>
>>   DOM.each( nodes, index => {
>>
>>     // |this| is the constructed instance
>>     this[ index ] = nodes[ index ];
>>
>>   });
>>
>>    this.length = nodes.length;
>> }
>>
>> // I might make my own API for
>> // manipulating my ListOfNodes
>> // ListOfNodes.prototype.foo...
>>
>>
>> var list = new ListOfNodes(".class");
>>
>> list;
>>
>> > [ div.class, div.class (use imagination) ]
>>
>>
>>
>> Hopefully this helps!
>>
>> Rick
>>
>
>
>
> --
>     Cheers,
>     --MarkM
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to