为什么window.location.reload
不能被回调?
// ▼定义一个函数,它会调用一个回调函数
function fn01 (fn){
fn && fn();
};
function callBackFn(){
console.log('★回调函数执行了★');
};
// ▼开始调用
fn01(callBackFn); //成功
fn01(window.print); //成功
fn01(window.location.reload); //失败【见下图】
//请问这个回调有啥特别吗?为啥不能用于回调
-
我知道可以用用匿名函数包裹 location.reload
然后可以实现回调
这里好奇,为什么不能被回调。
谢谢老司机的帮忙,谢谢你前台解答
-
感谢 `改名字很伤神 ` 的解答
看来果然是 this 变了,如下操作即可解决
fn01(window.location.reload.bind(location));
因为this改变了