Created
December 22, 2015 04:27
-
-
Save eternal44/19d2a013f2949cb09750 to your computer and use it in GitHub Desktop.
Trouble shooting infinite loop
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 getElementsByClassName = function(className){ | |
// Array of document element | |
var elementList = Array.prototype.slice.call( | |
document.body.querySelectorAll('*') | |
); | |
var results = []; | |
var count = elementList.length; | |
// check body independently since the above array doesn't contain 'body' | |
if (document.body.className === className) results.push(document.body); | |
// why doesn't the recursion trigger this countdown? | |
count -= 1; | |
if (count === 0) { | |
return results; | |
} else { | |
if(elementList[count].className === className){ | |
results.push(elementList[count]); | |
} | |
getElementsByClassName(className); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment