On Thu, May 31, 2012 at 3:08 PM, Rick Waldron <[email protected]>wrote:

>
> I'm going to take a stab at this, because I think I have a good
> understanding of what the JSFixed group is concerned about...
>

Hi Rick, thanks. That's exactly what I was hoping for.



>
>
> // 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.


>   //
>   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?



>   [].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