This document discusses challenges with enumerating over native JavaScript objects and some techniques for overcoming those challenges to emulate array-like behavior. It describes how ES5 methods don't work directly on objects, issues with iteration order and the length property, and presents a solution for encapsulating an object with array enumeration methods by defining indexed properties based on the object's properties. The solution allows treating objects like arrays while retaining key-value pairs and ordering.
12. WORKS?
var myObj={jozsi:2,tamas:5};
//wrap up our object extensional expressions to a method;
extendObj_as_array(myObj);
alert('myObj is now an emulated kind of array '+myObj.length);
//adding new, uninitialized property also as array indices;
myObj.aron=0;
13. NO...
//it is not possible to query the newly added index to myObj,
//because index is actually uninitialized until the length is queried;
alert('newly added index is undefined: '+myObj[2]);
//length is queried, indices are being updated!
alert('indices are updated: '+myObj.length);
//Now it is possible to query the newly added index to myObj;
alert('newly added index is now defined: '+myObj[2]);
//array functionality works on objects;
alert('mapping values as pixels: '+
[].map.call(myObj,function(s){return s+'px'}).join(', '));
//prints "2px, 5px, 0px"
15. SO ENCAPSULATE DIFFERENCES!
var enum=enumerable();
var enum=enumerable([]);
var enum=enumerable({});
var enum=enumerable(new enumerable);
16. LET US WORK!
//note! vacuum.db.tables[table] is a valid JavaScript Object.
enumerable(vacuum.db.tables[table]).
sort({againstVal:true,func:function(a,b){return a.frequency<b.frequency}}).
.forEach(function(i,val){
if(it.isTypeOf(val,[Object]).
ANDNOT({macro:'$this.id=='+self.defaultRecord}).true())
{
self.record(table,val.id);
}
return true;
});
17. FEATURES & PRINCIPLES
functional break support
Undo-redo transactions
Recursion support
returning interface consistency
Rock solid ordering management
18. FEATURES BASED ON ORDERING
Comparison between different types
Order based comparisons
fromItem/toItem support(bubbling)