1. 解构赋值初始值设定

  1. const { a, c = 1 } = { a: 2 }

2. 回顾原型对象和原型链

  1. const a = []
  2. a.__proto__ === Array.prototype
  3. Array.prototype.__proto__ === Object.prototype
  4. a.__proto__.constructor === Array

3. Promise

静态方法

  1. // p1 与 p2 是等价的
  2. let p1 = new Promise((resove, reject) => resolve())
  3. let p2 = Promise.resolve()
  4. // Promise.resolve() 可以接受一个参数(任意值),如果参数本身是一个Promise,则相当于一个空包装
  5. let p = new Promise(() => {})
  6. p === Promise.resove(p)
  7. p === Promise.resove(Promise.resove(p))
  8. // Promise.reject() 也接受一个参数,如果参数是个Promise,这个Promise就是返回拒绝的理由
  9. Promise.reject(Promise.resolve())

实例方法

  1. // then 可以接受两个参数(函数),成功执行第一个,拒绝执行第二个
  2. let p = new Promise((resolve, reject) => {
  3. resolve()
  4. }).then(
  5. () => console.log('resove'),
  6. () => console.log('reject')
  7. )
  8. // then catch finally 都会返回一个新的 promise 实例
  9. Promise.then() // Promise <pending>
  10. Promise.catch() // Promise <pending>
  11. Promise.finally() // Promise <pending>
  12. // catch 接受一个参数,实际上和执行then的第二个参数是一样的,是语法糖
  13. let p = Promise.reject()
  14. const onReject = () => {}
  15. p.catch(onReject) === p.then(null, onReject)

4. Array.prototype.reduce()

两个参数: 第一个参数是一个函数,可以接收四个参数 四个参数

  • accumulator 累计器
  • currentValue 当前值
  • currentIndex 当前索引
  • array 数组

第二个参数为初始值 initVal

5. URL && URI

URI:统一资源标识符,可以理解为一个人的身份证号
URL:统一资源定位符,可以理解为一个人的具体位置
通过身份证号和具体位置都可以找到这个人
URL 是 URl 的子集

6. hasOenProperty() && in

  1. // hasOwnProperty():看是不是对象自身下面的属性, 只在属性存在于实例中时才返回 true。 (不是通过原型链继承的)
  2. var A=function(){
  3. this.num=10;//对象自身下面的
  4. }
  5. A.prototype.num1=100;
  6. Object.prototype.num2=1000;
  7. var a = ew A();
  8. console.log(a1.num); // 10
  9. console.log(a1.num1); // 100
  10. console.log(a1.num2); // 1000
  11. console.log(a1.hasOwnProperty('num')); // true
  12. console.log(a1.hasOwnProperty('num1')); // false 继承来的
  13. console.log(a1.hasOwnProperty('num2')); // false 继承来的
  14. // in操作符,和hasOwnProperty一样的意义,包括继承的。
  15. console.log('num' in a); // true
  16. console.log('num1' in a); // true
  17. console.log('num2' in a); // true

7. post content-type 区别

https://www.jianshu.com/p/e54bedfb40f7

  • application/x-www-form-urlencoded
    • 提交的数据按照 key1=val1&key2=val2 的方式进行编码,key 和 val 都进行了 URL 转码
  • multipart/form-data
  • application/json
  • text/xml

8. encodeURIComponent & encodeURI 的区别

encodeURI方法不会对下列字符编码 ASCII字母 数字 ~!@#$&*()=:/,;?+’
encodeURIComponent方法不会对下列字符编码 ASCII字母 数字 ~!*()’
所以encodeURIComponent比encodeURI编码的范围更大。
实际例子来说,encodeURIComponent会把 http:// 编码成 http%3A%2F%2F 而encodeURI却不会。