On 11/23/10 13:05, David Herman wrote:
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
That misses the point of my question. Sure you can define the meaning of
for (k in MyNewFunction(o))
or
for (k in o.MyMethod())
However, I asked how a new object abstraction T would customize "keys", "values", and
"properties" just for instances of T so that instances of T could be usable under the standard
pattern:
for (k in keys(o)) ...
for (v in values(o)) ...
for ([k, v] in properties(o)) ...
Waldemar
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss