.call()方法:
将函数绑定到某个对象,call()不会创建一个函数,函数体内的this对象的值会被绑定到传入call()中的第一个参数的值,
例如:
let originPush=VueRouter.prototype.push;
//重写push方法
//第一个参数:告诉原来push方法往哪里跳转(传递哪些参数)
VueRouter.prototype.push=function(location,resolve,reject){
if(resolve && reject){
originPush.call(this,location,resolve,reject)
}else{
originPush.call(this,location,()=>{ },()=>{ })
}
}
当中.call()绑定的this为当前的VueRouter实例对象