Nov 18 notes

David Herman dherman at mozilla.com
Tue Nov 23 13:05:49 PST 2010


>> 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 ... },
>                ...
>            });
>        }
>    }

I left out the last step: clients would then use this via:

    var coll = new MyCollection();
    ...
    for (var x in coll.iterator()) {
        ...
    }

Dave



More information about the es-discuss mailing list