mirror of
				https://github.com/scinote-eln/scinote-web.git
				synced 2025-10-25 21:47:03 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			12 lines
		
	
	
	
		
			332 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			12 lines
		
	
	
	
		
			332 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| export function debounce(fn, wait){
 | |
|   let timer;
 | |
|   return function(...args){
 | |
|     if(timer) {
 | |
|         clearTimeout(timer); // clear any pre-existing timer
 | |
|     }
 | |
|     const context = this; // get the current context
 | |
|     timer = setTimeout(()=>{
 | |
|         fn.apply(context, args); // call the function if time expires
 | |
|     }, wait);
 | |
|   }
 | |
| }
 |