1. this

  1. function test () {} // Function Decaartion
  2. const test = function () {} // Function Expression
  3. const test = () => { // Arrow Function
  4. // 稳定的this指向
  5. }
  6. // 对象是一个容器, 不存在作用域
  7. var obj = {
  8. test: () => {
  9. console.log(this);
  10. const test2 = () => {
  11. console.log(this);
  12. }
  13. }
  14. }
  15. obj.test(); // window
  16. /**
  17. * 内部的xx
  18. *
  19. * Internal Property 属性
  20. * Internal Slots 插槽
  21. * Internal Methods 方法
  22. *
  23. * -> 格式 [[]]
  24. * -> 比如 [[Call]] -> 内部方法 -> 函数执行内部调用方法
  25. * -> [[Constructor]] -> traget -> function instance -> new Target,
  26. *
  27. * new -> 调用以下方法, 有该方法, 才可以执行
  28. * [[Constructor]] (argumentsList, fucntion instance)
  29. *
  30. */
  31. // 箭头函数不是一个构造器
  32. const test = () => {}
  33. const t = new test(); // Uncaght TypeError: test is not a constructor

2. Array.from

Array.from()方法对一个类数组, 和可迭代的对象创建一个新的浅拷贝的数组实例.

  1. var obj = {
  2. 0: 1,
  3. 1: 2,
  4. 2: 3,
  5. 3: 4,
  6. 4: 5,
  7. 5: 6,
  8. length: 6
  9. }
  10. // 返回一个数组, 奇数项, 每一项加上num
  11. Array.from(obj. function (item, index) {
  12. if (index % 2 === 0) {
  13. return item + this.num
  14. }
  15. }, {
  16. num: 500
  17. })

3. Temp_space

  1. var a = 1;
  2. // 参数有自己的空间, 参数作用域 -> Temp_space
  3. function test (a, b = function () { a = 2; console.log('--First--', a)}) {
  4. var a = 3;
  5. b();
  6. console.log('--Second--', a);
  7. }
  8. test(100);
  9. console.log('--Third--', a);
  10. // --First-- 2
  11. // --Second-- 3
  12. // --Third-- 1

4. Object.defineProperty, Object.defineProperties

  1. // 定义一个对象, c属性不能被枚举
  2. // {
  3. // a: 1,
  4. // b: 2,
  5. // c: 3
  6. // }
  7. /**
  8. * 默认值: false
  9. * writeable
  10. * configurable
  11. * enumerable
  12. */
  13. var obj = {};
  14. Object.defineProperties(obj, {
  15. a: {
  16. value: 1,
  17. enumerable: true
  18. },
  19. b: {
  20. value: 2,
  21. enumerable: true
  22. },
  23. c: {
  24. value: 3
  25. }
  26. })
  27. for (let key in obj) {
  28. console.log(key);
  29. }
  30. const arr = Object.keys(obj);
  31. console.log(arr);
  32. // Object.getOwnPropertyNames() 方法返回一个由指定对象的所有自身属性的属性名
  33. // (包括不可枚举属性, 但不包括 Symbol 值作为名称的属性) 组成的数组.
  34. const arrInner = Object.getOwnPropertyNames(obj);
  35. console.log(arrInner);