Add debounce function to JavaScript