From 71a0b32e41d92e2d64ef1712c940236d1e037927 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Thu, 31 Mar 2016 16:47:58 +0100 Subject: [PATCH] Fix #280 and #271 by being more careful about how we iterate over node lists in case they're live --- Readability.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Readability.js b/Readability.js index f8c12a5..821388c 100644 --- a/Readability.js +++ b/Readability.js @@ -155,7 +155,15 @@ Readability.prototype = { * @return void */ _forEachNode: function(nodeList, fn) { - return Array.prototype.forEach.call(nodeList, fn, this); + var i = 0; + while (nodeList[i]) { + var el = nodeList[i]; + fn.call(this, el, i, nodeList); + // Only increment i if the element is still in the list: + if (nodeList[i] == el) { + i++ + } + } }, /**