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 characters
var array = ["zero","first","second","third","fourth","fifth"]; | |
var closures = []; | |
for(var i=0, l=array.length; i<l; i++){ | |
closures.push(function(){return array[i]}); | |
} | |
closures[3](); | |
// Expected "third", but actually returns 'undefined', | |
// because js did not create a separate scope for the "for" block |
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 characters
function changeAllAnchorColor(color){ | |
var anchors = document.body.getElementsByTagName("a"); | |
for (var i = 0, l = anchors.length; i<l; i++){ | |
anchors[i].style.color = color; | |
} | |
} | |
var changeAllAnchorColorDesynched = desync(changeAllAnchorColor); | |
document.body.innerHTML = "<div id=container><a href=#>LOL This code does nothing...</a></div>"; |
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 characters
function benchmark(fn, id, it){ | |
id = id || new Date().toString(); | |
it = it || 100000; | |
if(typeof fn == "function"){ | |
console.time(id); | |
for (var i = 0; i< it; i++) fn(); | |
console.timeEnd(id); | |
} | |
} |