-
-
Save FoxMalder/0db20e45e0c77cfdbf321c44aaa15aec to your computer and use it in GitHub Desktop.
Revisions
-
zmts revised this gist
Aug 16, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ for(var i = 0; i < 5; i++) { ## let ``` for(let i = 0; i < 5; i++) { setTimeout(function() { console.log(i); }, 1000); -
zmts renamed this gist
Apr 16, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Javascipt. For. Var. Let. Closure. Event loop. ## var -
zmts revised this gist
Apr 16, 2018 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -35,4 +35,5 @@ for(var i = 0; i < 5; i++) { // >> 2 // >> 3 // >> 4 ``` `let` создает переменную в рамках блока `{}`. Иначе говоря `let` с каждым повторением цикла создает отдельный `scope`. Каждому повторению цикла соответствует своя независимая переменная `let`. Если внутри цикла есть вложенные объявления функций, то в замыкании каждой будет та переменная, которая была при соответствующей итерации. Исходя из этого `i` создается с каждым циклом в отельном скоупе и с каждым разом равна новому значению инкремента что собственно и будет выведено в лог. -
zmts revised this gist
Apr 16, 2018 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,6 @@ for(var i = 0; i < 5; i++) { ## let ``` for(var i = 0; i < 5; i++) { setTimeout(function() { @@ -36,6 +35,4 @@ for(var i = 0; i < 5; i++) { // >> 2 // >> 3 // >> 4 ``` -
zmts revised this gist
Apr 16, 2018 . 1 changed file with 22 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # Javascipt. Closure. Event loop ## var ``` for(var i = 0; i < 5; i++) { setTimeout(function() { @@ -17,4 +19,23 @@ for(var i = 0; i < 5; i++) { - Цикл отработал - 5 таймаутов создано - Переменная `i` равна `5` - Спустя секунду выполняются наши таймауты(пять штук) в которых анонимная ф-ция через замыкание выводит переменную `i` которая в этот момент уже равна `5` ## let ``` ``` for(var i = 0; i < 5; i++) { setTimeout(function() { console.log(i); }, 1000); } // >> 0 // >> 1 // >> 2 // >> 3 // >> 4 ``` ``` -
zmts revised this gist
Apr 15, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ for(var i = 0; i < 5; i++) { // >> 5 // >> 5 ``` Создавая переменную `i` в цикле (через `var`) мы обьявляем ее в области видимости той ф-ции в которой находится цикл. При прохожнении каждой итерации создаются таймауты и инкрементится переменная `i`. В момент завершения цикла переменная `i` будет равна `5` и все логи одновременно через одну секунду выведут `5`. - Цикл отработал - 5 таймаутов создано - Переменная `i` равна `5` -
zmts revised this gist
Apr 15, 2018 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,8 @@ for(var i = 0; i < 5; i++) { // >> 5 // >> 5 ``` Создавая переменную `i` в цикле (через `var`) мы обьявляем ее в области видимости той ф-ции в которой находится цикл. При прохожнении каждой итерации создаются таймауты и инкрементится переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. - Цикл отработал - 5 таймаутов создано - Переменная `i` равна `5` - Спустя секунду выполняются наши таймауты(пять штук) в которых анонимная ф-ция через замыкание выводит переменную `i` которая в этот момент уже равна `5` -
zmts revised this gist
Mar 24, 2018 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,5 +6,11 @@ for(var i = 0; i < 5; i++) { console.log(i); }, 1000); } // >> 5 // >> 5 // >> 5 // >> 5 // >> 5 ``` Создавая переменную `i` в цикле (через `var`) мы обьявляем ее в области видимости той ф-ции в которой находится цикл. При прохожнении каждой итерации создаются таймауты и инкрементируется переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. Цикл отработал, 5 таймаутов создано, переменная `i` равна `5`. Спустя секунду выполняются наши таймауты(пять штук) в которых анонимная ф-ция через замыкание выводит переменную `i` которая в этот момент уже равна `5`. -
zmts revised this gist
Mar 24, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,4 @@ for(var i = 0; i < 5; i++) { }, 1000); } ``` Создавая переменную `i` в цикле (через `var`) мы обьявляем ее в области видимости той ф-ции в которой находится цикл. При прохожнении каждой итерации создаются таймауты и инкрементируется переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. Цикл отработал, 5 таймаутов создано, переменная `i` равна `5`. Спустя секунду выполняются наши таймауты(пять штук) в которых анонимная ф-ция через замыкание выводит переменную `i` которая в этот момент уже равна `5`. -
zmts revised this gist
Mar 24, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,4 @@ for(var i = 0; i < 5; i++) { }, 1000); } ``` Создавая переменную `i` в цикле (через `var`) мы обьявляем ее в области видимости той ф-ции в которй находится цикл. При прохожнении каждого круга создаются таймауты и инкрементируется переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. Цикл отработал, 5 таймаутов создано, переменная `i` равна `5`. Спустя секунду выполняются наши таймауты(пять штук) в которых анонимная ф-ция через замыкание выводит переменную `i` которая в этот момент уже равна `5`. -
zmts revised this gist
Mar 24, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,4 @@ for(var i = 0; i < 5; i++) { }, 1000); } ``` Создавая переменную `i` в цикле (через `var`) мы обьявляем ее в области видимости той ф-ции в которй находится цикл. При прохожнении каждого круга создаются таймауты и инкрементируется переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. Цикл отработал, 5 таймаутов создано, переменная `i` равна `5`. Спустя секунду выполняются наши таймауты(пять штук) в которых выводится переменная `i` со значением `5`. -
zmts revised this gist
Mar 24, 2018 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,4 @@ for(var i = 0; i < 5; i++) { }, 1000); } ``` При прохожнении каждого круга создается таймаут и инкрементируется переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. Цыкл отработал, 5 таймаутов создано, переменная `i` равна `5`. Спустя секунду выполняются наши таймауты(пять штук) в которых выводится переменная `i` со значением `5`. -
zmts revised this gist
Mar 24, 2018 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,6 @@ for(var i = 0; i < 5; i++) { }, 1000); } ``` При прохожнении каждого круга создается таймаут и инкрементируется переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. Цыкл отработал, 5 таймаутов создано, переменная `i` равна `5`. Спустя секунду выполняются наши таймауты(пять штук) в которых выводится переменная `i` со значением `5`. При каждой итерации цикла переменная `i` через замыкание изменяется анонимной ф-цией находящейся в таймауте. -
zmts created this gist
Mar 24, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ # Javascipt. Closure. Event loop ``` for(var i = 0; i < 5; i++) { setTimeout(function() { console.log(i); }, 1000); } ``` При прохожнении каждого круга создается таймаут и инкрементируется переменная `i`. В момент завершения цикла переменная `i` будет равна `5`. Цыкл отработал, 5 таймаутов создано, переменная `i` равна `5`. Спустя секунду выполняются наши таймауты(пять штук) в которых выводится переменная `i` со значением `5`.