闭包
闭包
闭包,函数内部的函数就可以叫做是一个闭包
1 | function first(){ |
这种用闭包的方法比较少,因为其没什么大的作用。通常的用法是1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20function foo($index,callback){
var idx=$index*10;
document.write(idx+'<br>');
callback(idx);//此处,将方法的变量注入回调函数
}
//在回调中可以忽略掉注入的变量
foo(10,function(){
document.write('fff');
})
//100
//fff
//也可以将注入的变量显示化出来
foo(10,function($m){
document.write($m);
})
//100
//100
axios 例子
1 | axios.get(PATH, { |