20200306

@xiaojingzhao

Plan

  • 你不知道的 js p123 附录 A 混合环境 JavaScript
  • 你不知道的 js 第二部分 异步

Notes

宿主对象

  • 由宿主环境(例如:浏览器)创造的并提供给 js 引擎的变量
var a = document.createElement("div");
String(a); // [object HTMLDivElement]

全局 DOM 变量

DOM 如果带有 id,会在全局创建同名变量。

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

  <body>
    <div id="foo">hhhhhhhhhhhhhhh</div>
  </body>
  <script>
    console.log(foo);
  </script>
</html>

<script></script>

  • hoisting 不会从一个 <script></script> 到另一个 <script></script>
  • 共享命名空间
<script>
  foo(); // Error
</script>
<script>
  function foo() {}
</script>

More