深入理解JS notes | 青训营笔记

198 阅读2分钟

深入理解JS notes | 青训营笔记

basic concepts

birth

  1. similar to C syntax
  2. Java datatype and memory control
  3. Function is the first class
  4. prototypec inheritance

Develop

Mocha => Livescript => Javascript Why use ECMAScript ? Because MS used Jscript. in practice ECMAScript === js

JS Fundamental

  • single threaded
  • dynamic and weakly typed
  • object-oriented functional parameter => outcome //jQuery
  • interpret the class language
  • safty

Data Type

Reference type

const a.name ='zq';
const b = a;
console.log

Complex data type in JS can be changed (tdeclared with const) The base data type assignment is the value and CANNOT be changed

Scope

ES5ES6
global function++block

Variable Boost visit a variable before it is declared with const or let will cause Error var will cause Undefined function can be called before defined

how does js run

why byte code first?

  • to reduce memory cost

What is JIT a code appears twice or more , V8 will consider it as 'hot code' and transform it into machinecode.

what is "execution context"

  • variable env

  • lexial env

  • this

  • excutable code

    What are they

    • Global only one in a life. At the bottom of the call stack . attention the stack overflow
    • Function

    创建执行上下文的时候做了什么?

    • 绑定this
    • 创建词法环境
    • 创建变量环境

    • 词法环境: let const
    • 变量环境: var
    • Outer:指向外部的指针 (This part is not fully understood)

    实现了栈中垃圾回收

advanced tips

闭包/Closures

add==>in heap, memory not recycled

this

  • in Function , this => global/window
  • what about object
const name = 11;
const obj = {
    name: 'wq',
    showName(){
        console.log(this.name)
    } 
}
obj.showName()

apply,call,bind

Constructor

  1. 创建临时对象
  2. this指向对象
  3. 执行构造函数
  4. 返回临时对象

heap & stack

heap

  • 新生代 /小

    • 对象区域 
    • 空闲区域
  • 老生代(主垃圾回收器

      1. 标记清除 
      2. 内存整理
    • 由新生代进入
    • 清除后内存不连续

    耗时问题

Events Loop

之前不太懂

then 微任务,先于宏任务

What about Node?

summary

最后,为什么前半段笔记用英文:因为没装好输入法(汗,用的Ubuntu22.04,如果有好的输入法欢迎推荐 如果有单词拼写错误请指正

标题只是课程名称,我还不敢说理解JS

Events Loop 部分还不甚理解