diff --git a/README.md b/README.md index 3adae4b9e..895fc481f 100644 --- a/README.md +++ b/README.md @@ -3792,10 +3792,10 @@ isBrowserTabFocused(); // true Converts a `NodeList` to an array. -Use `Array.prototype.slice()` and `Function.prototype.call()` to convert a `NodeList` to an array. +Use spread operator inside new array to convert a `NodeList` to an array. ```js -const nodeListToArray = nodeList => Array.prototype.slice.call(nodeList); +const nodeListToArray = nodeList => [...nodeList]; ```
diff --git a/docs/browser.html b/docs/browser.html index 55f2fc98a..8105f2f04 100644 --- a/docs/browser.html +++ b/docs/browser.html @@ -211,7 +211,7 @@ hub.off
insertBefore(document.getElementById('myId'), '<p>before</p>'); // <p>before</p> <div id="myId">...</div>
 

isBrowserTabFocused

Returns true if the browser tab of the page is focused, false otherwise.

Use the Document.hidden property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden.

const isBrowserTabFocused = () => !document.hidden;
 
isBrowserTabFocused(); // true
-

nodeListToArray

Converts a NodeList to an array.

Use Array.prototype.slice() and Function.prototype.call() to convert a NodeList to an array.

const nodeListToArray = nodeList => Array.prototype.slice.call(nodeList);
+

nodeListToArray

Converts a NodeList to an array.

Use spread operator inside new array to convert a NodeList to an array.

const nodeListToArray = nodeList => [...nodeList];
 
nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]
 

observeMutationsadvanced

Returns a new MutationObserver and runs the provided callback for each mutation on the specified element.

Use a MutationObserver to observe mutations on the given element. Use Array.forEach() to run the callback for each mutation that is observed. Omit the third argument, options, to use the default options (all true).

const observeMutations = (element, callback, options) => {
   const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));