面试-JavaScript
宏任务与微任务
宏任务(普通脚本,setTimeout(),setInterval(),I/O,UI 渲染)
微任务(Promise,MutationObserver)
特殊任务 process.nextTick() 当前 event loop tick 将结束时且下一个 event loop tick 将开始时执行
特殊任务 setImmediate() 下一轮 event loop tick 的 macrotask 阶段将结束时执行
事件循环(Node)
同步任务
发出异步请求
规划定时器生效的时间
执行
process.nextTick()的回调timers - 处理
setTimeout()和setInterval()的回调函数I/O callbacks - 剩余的回调函数(
setTimeout()、setInterval()、setImmediate()及关闭请求回调函数之外)idle, prepare - 内部使用
poll - 轮询时间,等待还未返回的 I/O 事件
check - 执行
setImmediate()的回调close callbacks - 关闭请求的回调
继承模式
原型链继承
1
2SubType.prototype = new SuperType()
SubType.prototype.constructor = SubType构造函数继承
1
SuperType.call(this, superProp)
组合式继承
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16function SuperType(superProp){
this.superProp = superProp
}
SuperType.prototype.printSuperProp = function(){
console.log(this.superProp)
}
function SubType(superProp, subProp){
SuperType.call(this, superProp)
this.subProp = subProp
}
SubType.prototype = new SuperType()
SubType.prototype.constructor = SubType
SubType.prototype.printSubProp = function(){
console.log(this.subProp)
}寄生组合式继承
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16function SuperType(superProp){
this.superProp = superProp
}
SuperType.prototype.printSuperProp = function(){
console.log(this.superProp)
}
function SubType(superProp, subProp){
SuperType.call(this, superProp)
this.subProp = subProp
}
SubType.prototype = Object.create(SuperType.prototype)
SubType.prototype.constructor = SubType
SubType.prototype.printSubProp = function(){
console.log(this.subProp)
}
Object 三种冻结方式
Object.preventExtensions()|Object.isExtensible()| 阻止添加属性,原型不可更改Object.seal()|Object.isSealed()| 阻止添加属性,阻止移除属性,阻止配置属性(configurable 为 false),原型不可更改Object.freeze()|Object.isFrozen()| 阻止添加属性,阻止移除属性,阻止修改属性值,阻止配置属性(writable、configurable 为 false),原型不可更改

