On Sep 1, 2006, at 11:09 AM, michelts wrote:
> I want to know if there is some advantage except to the less code
> script, is there any performace gain? I want to know if there is a way
> to do a lambda function inside a map (as I can do in python), I think
> in something like:
>
> function openJSON() {
> deferred = loadJSONDoc('json/Cities');
> deferred.addCallback(function (json) {
> var newUL = UL(null, map(lambda(x, LI(null,
> A({'href':'test?id='+x.id}, x.name))), json));
> swapDOM('test', newUL);
> });
> }
In javascript, you can do better than python's lambda (which limits
itself to a single expression).
Javascript has proper anonymous functions:
function (x, y) { return x + y; }(1, 2) => 3
So, your code above:
function openJSON() {
var d = loadJSONDoc('json/Cities');
d.addCallback(
function (json) {
var newUL = UL(null, map(
function(x) {
return LI(null, A({href: 'test?id=' + x.id},
x.name)); },
json));
swapDOM('test', newUL);
}
);
}
Zac
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---