function XMLHttpRequestBreak(fun=()=>false){
    let f = XMLHttpRequest.prototype.open;
	
	let add = function(){
		XMLHttpRequest.prototype.open = function(...args){
			check = fun(args);
			if(check){
				throw check;
			}
			f.apply(this,args)
		}	
	};
	
	let remove = function(){
		XMLHttpRequest.prototype.open = f	
	};
	
	return {add, remove}
}

test = XMLHttpRequestBreak();
test.add()
test.remove()

test = XMLHttpRequestBreak(()=>"123");
test.add()
test.remove()

test = XMLHttpRequestBreak(console.log);
test.add()
test.remove()

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2021-09-28
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-17
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-08-17
  • 2021-10-13
相关资源
相似解决方案