I am executing the function delayFilter()
on keyup of an input box. I want to delay 1 second after the user stops typing and run the function filterProducts()
. However, when executing filterProducts()
inside of the setTimeout I get the console error "this.filterProducts is not a function". This function gets called fine when outside of the setTimeout. Why is this error being thrown?
delayFilter() {
let timeout = null;
clearTimeout(timeout);
timeout = setTimeout(function() {
this.filterProducts();
}, 1000);
}
filterProducts() {
//do stuff
}