Created
May 8, 2014 11:47
-
-
Save LESTADru/aa956f65d86441ffb326 to your computer and use it in GitHub Desktop.
Функция создающая армию стрелков. При ее вызове, каждый стрелок выводит свой номер.
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
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>Следующий код создает массив функций-стрелков shooters. | |
По замыслу, каждый стрелок должен выводить свой номер:</title> | |
</head> | |
<body> | |
<script> | |
'Use strict' | |
function makeArmy() { | |
var shooters = []; | |
for(var i=0; i<10; i++){ | |
var shooter = function me(){ | |
alert(me.i); | |
}; | |
shooter.i = i; | |
shooters.push(shooter); | |
} | |
return shooters; | |
} | |
var army = makeArmy(); | |
army[0](); | |
army[5](); | |
army[7](); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment