Hi Paolo,

The ES6 iterator protocol is what you're looking for. See:
* https://hacks.mozilla.org/2015/04/es6-in-depth-iterators-and-the-for-of-loop/ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator

Alongside with the computed property syntax, you should be able to achieve what you want. Something along the lines of:
------------
function makeIterableEventList(el){
    el[Symbol.iterator] = function(){ /* define iterator here*/ }
    return el;
}

  events: {
    [Symbol.iterator]: function(){ /* define iterator here*/ }
    mainview: makeIterableEventList({
      focus(event) {},
    }),
    filter: makeIterableEventList({
      input(event) {},
    }),
  },

  this.boundEventHandlers = [
    for ([elementName, events] of this.events)
    for ([eventName, handler] of events)
    [elementName, eventName, handler.bind(this)]
  ];
---------------

It should work in Firefox today (at least the Symbol.iterator and computed object prop parts. Not 100% sure about the array comprehension as I haven't tested)

David

Le 22/07/2015 14:42, Paolo Amadini a écrit :
On 7/21/2015 12:07 PM, Tom Schuster wrote:
Aside: Please also try avoid using Iterator().

What would be the alternative to Iterator() when I need to iterate and
easily assign both keys and values of an object to local variables?

See for example <https://bugzilla.mozilla.org/show_bug.cgi?id=980828>:

  this.boundEventHandlers = [
    for ([elementName, events] of Iterator(this.events))
    for ([eventName, handler] of Iterator(events))
    [elementName, eventName, handler.bind(this)]
  ];

There's more context on the bug for the specific example (the bug is
about supporting destructuring in comprehensions in the first place)
but my concern in general is that I've failed to find an alternative
to Iterator() that is as expressive.

Cheers,
Paolo
_______________________________________________
firefox-dev mailing list
firefox-...@mozilla.org
https://mail.mozilla.org/listinfo/firefox-dev

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to