JavaScript 高级


code 编译过程:源代码 -(GO - GlobalObject | VO - variable Object | 变量提升 - undefined)> AST -> ByteCode -> Run

  • 函数执行栈 -> GO -> VO -> AO
    • 函数执行上下文 (作用域定义地方决定) AO
    • GEC Global Excution Context 全局执行上下文
    • FEC Function Excution Context 函数执行上下文
    • es6 环境变量 -> variable Enviroment 环境记录

垃圾回收算法:

1. 引用计数

  • 缺陷:循环引用
  1. 标记清除
  • 从 root 开始查找

高级函数:一个函数的参数是另一个函数或者一个函数的返回值是一个函数

# 数组的高阶函数

// 1. arr.filter 过滤
// 2. arr.map
// 3. arr.reduce
const nums = [3, 1, 4, 5, 546, 546, 7, 6, 78, 9, 0];
2;
let res;

res = nums.filter(num => num > 5);
console.log(res, "filter");

res = nums.map(item => item * 10);
console.log(res, "map");

res = nums.reduce((pre, next) => pre + next, 0);
console.log(res, "reduce");

// nums.forEach(item => console.log(item));

res = nums.find(item => item === 78);
console.log(res, "find");

res = nums.findIndex(item => item === 78);
console.log(res, "findIndex");

var firend = [
  { name: "why", age: 18 },
  { name: "why1", age: 180 },
  { name: "why2", age: 1800 },
  { name: "why3", age: 18000 }
];
res = firend.find(item => item.name === "why2");
console.log(res);
res = firend.findIndex(item => item.name === "why2");
console.log(res);

# 作用域链 (scope china) -> (AO + GO)

# 模板字符串调用函数

function test (..args) {}

test`aaa`

# 纯函数

  • 确定的输入和输出 没有产生任何副作用 (改变,输出,事件等)

文章作者: 神奈川
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 神奈川 !
  目录