Created
September 12, 2015 14:53
-
-
Save TiagoWinehouse/ada09913fd17a792af9f to your computer and use it in GitHub Desktop.
Usando o call para chamar funções anônimas
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 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