Implement bind() | Frontend Interview question | call(),apply() and bind() difference

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • This video describes how to implement bind() in javascript which is very frequently asked question in Javascript interviews/frontend interviews.
    we will also cover the differences between call() ,apply() and bind() methods in javascript.

Комментарии • 3

  • @patni1234561
    @patni1234561 3 года назад +1

    This is assuming call, apply works. I fail to understand which browser supports call , apply but doesn't support bind. How do we implement the same behaviour without using apply or call?

    • @InterviewJs
      @InterviewJs  3 года назад +1

      The basic idea of this interview question is to understand your basic knowledge about call, apply and bind and how can you use them in situations where needed.
      You can work on this sample code to create your own bind without using inbuilt call or apply.
      create your own Call method:
      Function.prototype.customCallMethod = function(anyOtherThis) {
      anyOtherThis.fnName = this;
      anyOtherThis.fnName();
      };
      we can take this further to create a detailed video on this if required.

    • @patni1234561
      @patni1234561 3 года назад

      @@InterviewJs thank you. Yes I understand this is a interview question, appreciate your video and your response. However, I felt the question is wrong in the first place as we assume something works & the other thing doesn't, which is not the case.
      Also one don't really implement polyfills in a day to day job. I exactly know how call apply bind works, but I was rejected because I wasn't able to answer this question.
      Anyway, this question is asked & thank you for simplified solution in your video.