js异步发展的流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Function.prototype.before=function(callback){
let self=this;
return function(){
callback();
self.apply(self,arguments)
}
}
function fn(val){
console.log('有一定的功能了',val);
}
let newFn=fn.before(()=>{
console.log('在函数执行之前执行这段...')
})
newFn()

// 在函数执行之前执行这段...
// 有一定的功能了 undefined

newFn(1)
// 在函数执行之前执行这段...
// 有一定的功能了 1