Q16 Polyfill of setInterval | Javascript Interview Questions | Most asked questions in interview

Поділитися
Вставка
  • Опубліковано 14 жов 2024

КОМЕНТАРІ • 13

  • @letsexplore7590
    @letsexplore7590 Рік тому

    Very underrated channel on UA-cam for fronend. One day u are gonna have huge subscriber. Content are awesome here.
    Gonna recommend this channel to my friends

  • @EdwinManual
    @EdwinManual Рік тому +1

    This is a criminally underrated channel. There aren’t much resources for FE engineering like BE engineering.

  • @saharshjain922
    @saharshjain922 Рік тому +1

    Very good stuff. in clearInterval Poly shouldn't it be clearTimeoutPoly(intervalMap[id]) ?

    • @aliasgartaksali7785
      @aliasgartaksali7785 Рік тому

      yes, it worked because both id's were same, if we generated random number then it will break

  • @rupeshsharma3754
    @rupeshsharma3754 Рік тому

    How can we create polyfill of "new" keyword in Javascript? If possible could you please make video on this?

  • @aniketpadmansh4213
    @aniketpadmansh4213 Рік тому

    This is some great stuff... 😁🔥

  • @aadarshverma9925
    @aadarshverma9925 Рік тому

    At line 23, it should be clearTimeoutPoly(intervalMap[id]) instead of clearTimeoutPoly(id)?

  • @akshitatyagi5234
    @akshitatyagi5234 Рік тому

    Im getting a "requestIdleCallback is not defined" error. Coul not find solution anywhere

  • @AmanAnand-ym8wv
    @AmanAnand-ym8wv Рік тому

    I think we don't need a setTimeout. we can create and update the start Time as we did before in setTimeout but not delete the timerId once time is elapsed
    function createTimeInterval(){
    let intervalId = 1;
    let storedIntervals = {};
    function myInterval(callback,delay,...args){
    let id = intervalId++;
    let start = Date.now();
    storedIntervals[id] = true;
    function recur(){
    if(!storedIntervals[id]) return;
    if(Date.now() > start+delay){
    callback.apply(this,...args);
    start = Date.now();
    }
    requestIdleCallback(recur);
    }
    requestIdleCallback(recur);
    return id;
    }
    function myclearInterval(id){
    if(storedIntervals[id]){
    delete storedIntervals[id];
    }
    }
    return {myInterval, myclearInterval};
    }
    Please let me know if this is wrong

    • @akshay-kumar-007
      @akshay-kumar-007 Рік тому

      This should actually work and in my opinion a cleaner solution.