fonction fléchée


const $ = document.querySelector;
// TypeError: Illegal invocation
const el = $('.some-element');
const $ = document.querySelector.bind(document);
// Or:
const $ = (...args) => document.querySelector(...args);

Parcours du DOM : générateur

 <!DOCTYPE html>

<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <ul>
    <li>hello 1</li>
    <li>hello 2</li>
    <li>hello 3</li>
  </ul>
  <script>
    function* search(node) {
      if (!nodereturn;
      yield node;
      yield* search(node.firstChild);
      yield* search(node.nextSibling);
    }
    document.body.insertAdjacentHTML("beforeend"`<h1> the DOM`)
    const nodes = [];
    for (let node of search(document.body)) {
      if (node.localNamenodes.push(node.localName)
    }
    document.body.insertAdjacentHTML("beforeend"nodes)

  </script>
</body>

</html>