On Thu, May 31, 2012 at 5:40 PM, Mark S. Miller <[email protected]> wrote:
snip
>
> If the predicate means what I think it should mean, I can offer some
> examples of when I would do this. If the predicate means anything else
> that's been advocated on this thread, such as "fat arrow or bound", then I
> have no idea why anyone would ever write code as above. Can anyone offer a
> concrete example? If not, then I suggest that these other proposed meanings
> are simply not useful.
>
>
Mark,

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


// 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
  //
  if ( !Function.isBound(callbackFn) ) {
    // When not explicitly bound,
    // DOM.each sets |this| to the object being iterated
    bound = callbackFn.bind( elems );
  }

  [].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
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to