4 ms·
That's actually way slower because you're doing a comparison within an iteration. That's putting an if statement inside a loop while the result is the same for
by invisible 17y ago
That's actually way slower because you're doing a comparison within an iteration. That's putting an if statement inside a loop while the result is the same for every iteration.
- ars 17y agoComputers are not that slow these days :) It reduces complexity and a global, which is far more important. And that blink loop is probably not that big - just how many blink tags do you have? I don't use it for blink loops anyway, I use it for toggle on/off, where keeping state for each element individually is pretty important.
- invisible 17y agoYou're accessing the DOM every iteration, so I'd bet that it does matter somewhat if blink is used a lot. You can avoid polluting by make it an actual function and then setting the function.blinkOn instead. You're right: individually swapping them this works better, but the intent is to have them all off or all on. (function() { var blinkIterator = function() { var blinks = document.getElementsByTagName("blink"), onOff = blinkIterator.blinkOn ? "" : "hidden"; for (var i = 0, l = blinks.length; i < l;) blinks[i++].style.visibility = onOff; blinkIterator.blinkOn ^= 1; }; blinkIterator.blinkOn = 1; window.setInterval(blinkIterator, 750); })();