Created
July 26, 2011 12:06
-
-
Save cmilfont/1106606 to your computer and use it in GitHub Desktop.
Exemplo de List Comprehensions com Javascript 1.7 rodando no SpiderMonkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var users = [ {id: 1, name: "Christiano Milfont"}, {id: 2, name: "Christian Martins"}]; | |
var empresas = [ {name: "Fortes", user_id: 2}, {name: "Milfont", user_id: 1}, {name: "Fluxus", user_id: 2} ]; | |
var collection; | |
var filter = function(user, empresa) { | |
return (user.id === empresa.user_id && user.name === "Christian Martins"); | |
} | |
//bug do firebug no firefox 4, precisa rodar com eval | |
eval("collection = [ \ | |
{user: user, empresa: empresa} \ | |
for each (user in users) \ | |
for each (empresa in empresas) \ | |
if (filter(user, empresa))]; \ | |
"); | |
for (var i in collection){ | |
console.log( collection[ i ] ); | |
} |
Eval is EVIL!
Deixem de frescura, aqui o Eval é por uma boa causa, o Firebug crasha se tentar direto nessa versão do firefox
Não quero saber... vendeu a alma. Eval is evil.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eval is evil!