Last active
December 8, 2016 18:40
-
-
Save klinyecviktor/4a0c4d3da0242cd55eeedd723d1e0cae to your computer and use it in GitHub Desktop.
Technical Interview
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 a = function() { | |
for (var i = 0; i < 10; i++) { | |
setTimeout(function () { | |
console.log(i); | |
}) | |
} | |
} | |
a(); | |
// bind | |
var a = function() { | |
for (var i = 0; i < 10; i++) { | |
setTimeout(function() {console.log(this.i)}.bind({i: i})) | |
} | |
} | |
a(); | |
// (function(){})() | |
var a = function() { | |
for (var i = 0; i < 10; i++) { | |
setTimeout((function () { | |
console.log(i); | |
})(i)) | |
} | |
} | |
a(); | |
// variable declaration | |
var a = function() { | |
for (var i = 0; i < 10; i++) { | |
setTimeout(function(i) {console.log(i)}, 0, i) | |
} | |
} | |
a(); | |
===== | |
var a = function() { | |
function time(i) { | |
setTimeout(function() {console.log(i)}) | |
} | |
for (var i = 0; i < 10; i++) | |
time(i) | |
} | |
a(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment