Nov 18 notes

David Herman dherman at mozilla.com
Tue Nov 23 13:03:50 PST 2010


>>   for (k in keys(o)) ...
>>   for (v in values(o)) ...
>>   for ([k, v] in properties(o)) ...
> 
> What are "keys", "values", and "properties" here?  Global functions?

Those are API's suggested in the strawman:iterators proposal. They would be importable from a standard module.

>  How would a new object abstraction T customize them just for instances of T?

By writing its own custom iteration protocol via proxies with the iterate() trap implemented appropriately. E.g.:

    function MyCollection() { }
    MyCollection.prototype = {
        iterator: function() {
            var self = this;
            return Proxy.create({
                iterate: function() { ... self ... },
                ...
            });
        }
    }

Dave



More information about the es-discuss mailing list