function XMLHttpRequestFilter(){
    let base = XMLHttpRequest.prototype.open;
	
	let filter_list = [];
	
	let add = function(fun, key='_fn'){
		filter_list.push([key, fun])
		XMLHttpRequest.prototype.open = function(...args){
			filter_list.map(x=>{
				let check = x[1](args)
				if(check){
					throw check; 
				}
			});
			base.apply(this,args)
		}	
	};
	
	let remove = function(key='_fn'){
		filter_list = filter_list.filter(x=>x[0]!=key);
	};
	
	let removeAll = function(){
		filter_list.length=0;
		XMLHttpRequest.prototype.open = base	
	};
	
	return {add, remove, removeAll}
}

t.add(console.log, 'k1')
t.add(console.dir, 'k2')
t.add(console.log, 'k3')

t.remove('k2')
t.removeAll()

t.add(console.log, "k1")
t.add(()=>"123", 'k2')
t.add(console.dir, "k1")

t.remove("k2")

  

相关文章:

  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
猜你喜欢
  • 2021-08-25
  • 2021-12-26
  • 2021-07-08
  • 2022-12-23
  • 2021-10-13
  • 2022-01-07
相关资源
相似解决方案