Skip to content

Instantly share code, notes, and snippets.

@klinyecviktor
Last active December 8, 2016 18:40
Show Gist options
  • Save klinyecviktor/4a0c4d3da0242cd55eeedd723d1e0cae to your computer and use it in GitHub Desktop.
Save klinyecviktor/4a0c4d3da0242cd55eeedd723d1e0cae to your computer and use it in GitHub Desktop.
Technical Interview
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