function assoc(obj) {
obj = obj || {};
function Assoc() {}
Assoc.prototype.iterator = ...
Das ist natürlich Murks, jedesmal den Iterator im Prototyp neu zu setzen. So sollte es besser funktionieren:
~~~javascript
function Assoc(obj) {
if(!(this instanceof Assoc))
return new Assoc(obj);
obj = obj || {};
this.__iterator__ = function() {
let it = Iterator(obj);
return {
next : function() {
while(true) {
let [key, value] = it.next();
if(obj.hasOwnProperty(key))
return [key, value];
}
}
};
};
}
let a = Assoc({ spam : 'eggs'});