I'm calling searchkeyword function on keyUp. I want to cancel/clearTimeout $emit when new letter is typed quickly, so that only few times $emit is called. But console being called/debounce on every searchkeyword call.
methods: {
searchKeyword : function() {
var scope = this;
(this.debounce(function(){
scope.$emit("search-keyword", scope.keyword);
console.log("Called");
},350))();
},
debounce: function (func, delay) {
var timeout;
return function() {
const context = this;
const args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(context, args), delay);
}
}
}