1. 解构赋值初始值设定
const { a, c = 1 } = { a: 2 }
2. 回顾原型对象和原型链
const a = []
a.__proto__ === Array.prototype
Array.prototype.__proto__ === Object.prototype
a.__proto__.constructor === Array
3. Promise
静态方法
// p1 与 p2 是等价的
let p1 = new Promise((resove, reject) => resolve())
let p2 = Promise.resolve()
// Promise.resolve() 可以接受一个参数(任意值),如果参数本身是一个Promise,则相当于一个空包装
let p = new Promise(() => {})
p === Promise.resove(p)
p === Promise.resove(Promise.resove(p))
// Promise.reject() 也接受一个参数,如果参数是个Promise,这个Promise就是返回拒绝的理由
Promise.reject(Promise.resolve())
实例方法
// then 可以接受两个参数(函数),成功执行第一个,拒绝执行第二个
let p = new Promise((resolve, reject) => {
resolve()
}).then(
() => console.log('resove'),
() => console.log('reject')
)
// then catch finally 都会返回一个新的 promise 实例
Promise.then() // Promise <pending>
Promise.catch() // Promise <pending>
Promise.finally() // Promise <pending>
// catch 接受一个参数,实际上和执行then的第二个参数是一样的,是语法糖
let p = Promise.reject()
const onReject = () => {}
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
// hasOwnProperty():看是不是对象自身下面的属性, 只在属性存在于实例中时才返回 true。 (不是通过原型链继承的)
var A=function(){
this.num=10;//对象自身下面的
}
A.prototype.num1=100;
Object.prototype.num2=1000;
var a = ew A();
console.log(a1.num); // 10
console.log(a1.num1); // 100
console.log(a1.num2); // 1000
console.log(a1.hasOwnProperty('num')); // true
console.log(a1.hasOwnProperty('num1')); // false 继承来的
console.log(a1.hasOwnProperty('num2')); // false 继承来的
// in操作符,和hasOwnProperty一样的意义,包括继承的。
console.log('num' in a); // true
console.log('num1' in a); // true
console.log('num2' in a); // true
7. post content-type 区别
- 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却不会。