Skip to content

Instantly share code, notes, and snippets.

@tcase360
tcase360 / debounce-with-exit.js
Created April 27, 2019 17:57
Debounce with an exit timeout
/**
* Create a function that accepts a function and then
* fires only after it hasn't been called for 250ms
*
* Once that is done, create an "exit" functionality
* that will take an "exit" number, higher than the
* "wait" variable, that will call the function regardless
*/
// params - fn, @{Callback}, wait @{Integer}
this.coffee = false;
function Employee1(coffee) {
this.coffee = coffee;
const enterOffice = () => {
if(this.coffee) {
console.log('good morning!');
} else {
console.log('this sucks');
@tcase360
tcase360 / this-example-1.js
Last active August 31, 2017 03:12
Example for this
this.coffee = false;
function Employee(coffee) {
this.coffee = coffee;
const enterOffice = function() {
if(this.coffee) {
console.log('good morning!');
} else {
console.log('this sucks');
@tcase360
tcase360 / debounce.js
Last active April 20, 2020 20:37
Debounce function in ES6
const debounce = (fn, time) => {
let timeout;
return function() {
const functionCall = () => fn.apply(this, arguments);
clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
}
}