Here are some more suggestions for additions to Base/Iter. These are
all functions that I currently use multiple times in my own code and
seem generic enough.
Thanks,
Chris
// reverse of Base.items, I believe this was semi-approved by Bob
earlier
fromItems : function(items) {
var obj = {};
MochiKit.Iter.forEach(items, function(item) {
obj[item[0]] = item[1];
});
return obj;
}
// round out logical operators
logxor: function (a, b) { return (a || b) && !(a && b); }
// reverse of itemgetter (perhaps there is a better name)
getteritem: function (obj) {
return function (arg) {
return obj[arg];
}
}
// a simple way to do a deep clone
cloneJSON : function (value) {
return MochiKit.Base.evalJSON(MochiKit.Base.serializeJSON(value));
}
// like next, but return null if there are no more left instead of
throwing exception
nextOrNull : function(iter) {
try {
return iter.next();
} catch (e) {
if (e != MochiKit.Iter.StopIteration)
throw e;
return null;
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---