Skip to content

Instantly share code, notes, and snippets.

@TiagoWinehouse
Created September 12, 2015 14:53
Show Gist options
  • Save TiagoWinehouse/ada09913fd17a792af9f to your computer and use it in GitHub Desktop.
Save TiagoWinehouse/ada09913fd17a792af9f to your computer and use it in GitHub Desktop.
Usando o call para chamar funções anônimas
var animais = [
{ especie: 'Lion', nome: 'King' },
{ especie: 'Whale', nome: 'Fail' }
];
for (var i = 0; i < animais.length; i++) {
(function(i) {
this.print = function() {
console.log('#' + i + ' ' + this.especie
+ ': ' + this.nome);
}
this.print();
}).call(animais[i], i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment