1

Как передать в callback delay ? Так не работает

   const func = debounce(function (array = [], delay) {
        ...//
    }, delay);

   export default (fn, time) => {
     let timeout;

     return function() {
      const functionCall = () => fn.apply(this, arguments);

      clearTimeout(timeout);
      timeout = setTimeout(functionCall, time);
     };
  };
7
  • 1
    Что не работает?
    – Roman C
    30 апр 2018 в 8:13
  • delay переданный не видит
    – werty
    30 апр 2018 в 10:26
  • покажи что не видит
    – Roman C
    30 апр 2018 в 10:43
  • jsfiddle.net/cndz9a26/1 вот так не работает не могу пробросить delay в колбэк
    – werty
    30 апр 2018 в 12:41
  • говорит что unresolved variable
    – werty
    30 апр 2018 в 12:41

1 ответ 1

0

const debounce = (fn, time) => {
    let timeout;

    return function() {
        const functionCall = () => fn.apply(this, arguments);

        clearTimeout(timeout);
        timeout = setTimeout(functionCall, time);
    };
};

const delay = 1000;

const append = debounce(
  () => {
    console.log("three");
  },
  delay
);

console.log("one");
append();
console.log("two");

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.