[Pkg-mozext-commits] [requestpolicy] 140/280: use `isArray()` instead of `instanceof, fixes #565

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:13 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 4abbf09d778c517c078633a67275ee69bbc3b976
Author: Martin Kimmerle <dev at 256k.de>
Date:   Thu Jan 15 18:16:49 2015 +0100

    use `isArray()` instead of `instanceof, fixes #565
---
 src/content/lib/utils/dom.jsm | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/content/lib/utils/dom.jsm b/src/content/lib/utils/dom.jsm
index ce04bc0..899f6fa 100644
--- a/src/content/lib/utils/dom.jsm
+++ b/src/content/lib/utils/dom.jsm
@@ -35,16 +35,16 @@ let DOMUtils = {};
  * Function that takes a DOM Element or an Array of DOM elements and removes
  * all their children.
  */
-DOMUtils.removeChildren = function(aElement) {
-  if (aElement instanceof Array) {
-    // if aElement is an Array, recursively call `DOMUtils.removeChildren` on
-    // its elements
-    while (aElement.length > 0) {
-      DOMUtils.removeChildren(aElement.pop())
-    }
-  } else {
-    while (aElement.firstChild) {
-      aElement.removeChild(aElement.firstChild);
+DOMUtils.removeChildren = function(aElements) {
+  // If aElements is not an Array, put the element in an Array.
+  let elements = Array.isArray(aElements) ? aElements : [aElements];
+  // Note on `isArray` (above):
+  //     using `instanceof` did not work. For details see
+  //     https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
+
+  for (let el of elements) {
+    while (el.firstChild) {
+      el.removeChild(el.firstChild);
     }
   }
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list