Polyfill for bind method | Javascript Interview Questions

Поділитися
Вставка
  • Опубліковано 3 лют 2019
  • Polyfill for bind function is one of the most important question in frontend javascript interviews. I've faced this question a lot of time while giving interviews and have also started asking this myself while taking interviews.
    This video tutorial covers a step by step approach to write our own implementation of bind method in Javascript.
    Link to the code - codepen.io/akshaymarch7/pen/L...
    If you have any suggestions in mind, any topics you want me to discuss or any specific problem, feel free to ping me anytime on LinkedIn, Facebook or just email me directly. I would be happy to help you.
    If you find my videos helpful,
    then please support this channel by buying a coffee,
    www.buymeacoffee.com/akshayma...
    Cheers,
    Akshay Saini
    akshaysaini.in
    Would love to Stay Connected with you ❤️
    LinkedIn - / akshaymarch7
    Instagram - / akshaymarch7
    Twitter - / akshaymarch7
    Facebook - / akshaymarch7
    #Javascript #JavascriptInterviewQuestions #AkshaySaini

КОМЕНТАРІ • 274

  • @ruchirai5775
    @ruchirai5775 4 роки тому +151

    @Akshay before this video I went through lot of blogs like medium, stackoverflow to understand binds internal implementation, this is the most easiest and awesome explanation I have ever seen for BIND.Thank you so much :) Can you also make a video on implementing own promise and implementing own virtual DOM ?

    • @pioneer7161
      @pioneer7161 2 роки тому +6

      medium pe bass gyaan milta hai.. real life scenario nhi milne wale..
      akshay bhai k liye meri taraf se 2 likes

    • @girishmehra8383
      @girishmehra8383 10 місяців тому +3

      @@pioneer7161 bhai 2 likes mat kar ek hi kar 2 karega toh jo ek kiya woh Bhi hat jayega😜😜

  • @KrishnaMishra-fl6pu
    @KrishnaMishra-fl6pu 3 роки тому +41

    Not only you taught us how to make bind function but also u have taught us how to think...❤️ Loving your videos and hence loving js

  • @pranitapanigrahi3517
    @pranitapanigrahi3517 3 роки тому +5

    I do have knowledge on Javascript concepts but whenever I want to prepare for interviews or want to refresh my understanding about those concepts ,your youtube channel is the first thing which comes to my mind. I cant stop thanking you for sharing your knowledge in such a detailed way.

  • @raveenasharma4645
    @raveenasharma4645 2 роки тому +8

    Your explanation about basic concepts is so good. I've been watching the entire JS series! Thank you so much

  • @kirank3368
    @kirank3368 4 роки тому +4

    You are simply awesome 👏🏽 The way you clear things and make us understand it very straight is fabulousness. Thanks bro 🙏

  • @rohitanand1475
    @rohitanand1475 4 роки тому

    I never knew what polyfill was. It appeared to me as a advanced concept. But you have explained this topic very well and i think i have got a good grasp of it. THANKS A LOT.

  • @sandeepa4116
    @sandeepa4116 3 роки тому +5

    Ultimate explanation Akshay! Really amazing work of helping so many like me out there. God bless you 🙏🏻
    "In the interviews, if we don't want to be SHY, then we gotta learn from AkSHAY" 😎

  • @abhishekmulay759
    @abhishekmulay759 3 роки тому +28

    Dude you are amazing! I am a senior engineer and I know all these concepts I still come back to your videos to refresh my knowledge before interviews! Keep up the great work.

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

      How does this variable refer printName method inside myBind function? I am confused here.

    • @shellyshack9364
      @shellyshack9364 8 місяців тому

      6:37 nee,

  • @sumitjangir48
    @sumitjangir48 4 роки тому +7

    Bro.. You are doing social service for us... Thanks for your help.. Keep helping.. keep growing...

  • @akarshsrivastava8890
    @akarshsrivastava8890 3 роки тому +9

    I can clearly see closure application in poly filling the bind function. 😅 Thanks for providing this power to see through code, Akshay.

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

    Prototype ,proptotypal inheritence ,prototype chaining ,call bind apply all i have learnt from you now everything was implemented here and i understood it with utmost efficacy thanks Akshay

  • @shadahmedmasthikund8965
    @shadahmedmasthikund8965 4 місяці тому

    The best teacher I've ever got for how to learn and what to learn in java script... Akshay sir❤

  • @jaydeep405
    @jaydeep405 4 роки тому

    You motivate me. Your teaching skills are fabulous. I learnt a lot by just viewing a few videos of yours 😊 Keep up the good work

  • @priyankasingh-no1oz
    @priyankasingh-no1oz 3 роки тому

    Hi @Akshay, Thank you so much for making these videos. I saw your videos and cracked too many interviews for Front End Developer. Thank you so much again.

  • @mohityadav21
    @mohityadav21 2 роки тому +8

    Short solution:
    Function.prototype.mybind = function (...args) {
    return (...args2) => this.call(...args, ...args2);
    };
    "this" inside the arrow function refers to the function on which mybind function is called.

  • @raghavendrasao6959
    @raghavendrasao6959 4 роки тому +6

    Hi @akshay, u r doing a great job !!
    i have one small suggestion.
    in line no 17 i think we can add return before obj.apply(....) also, because if printName will return something then our mybind will return always undefined.

  • @palakdua593
    @palakdua593 3 роки тому

    Really impressive way of teaching and the topics/questions are superb.

  • @mdridoy-ef2pw
    @mdridoy-ef2pw 2 роки тому +1

    Not a even the og youtubers discuss these core topics like you.
    Thank you!
    More simpler version of the myBind function:
    Function.prototype.myBind = function (...args1) {
    return (...args2) => this.call(...args1, ...args2);
    }

  • @pragyahazari4154
    @pragyahazari4154 4 роки тому

    Hi Akshay,
    First of all you explain things really well, in a very simple and crisp manner. Please make a video on async await. This concept has always puzzled me and still not very confident about it. Please its a humble request.

  • @pintzprajapati
    @pintzprajapati 2 роки тому

    Learned first time and wow it was super easy because of your teaching method. thanks bro

  • @mohammedg485
    @mohammedg485 2 роки тому

    I'm glad i found your channel, its gold. keep it up brother.

  • @asitkumar8543
    @asitkumar8543 2 роки тому +7

    The bind() method creates a new function, when invoked, has the this sets to a provided value.
    The bind() method allows an object to borrow a method from another object without making a copy of that method. This is known as function borrowing in JavaScript.

  • @charans1845
    @charans1845 3 роки тому

    Excellent explanation. Akshay bro u are fav teacher of mine..

  • @Gamer-gw6nj
    @Gamer-gw6nj Рік тому +2

    Function.prototype.myBind = function (...args) {
    let ref = args[0];
    let params = args.slice(1);
    let obj = this;
    return function (...args2) {
    args[0].gt = obj; //This is my impelementation of the bind polyfill, I haven't used apply method over here.
    args[0].gt(...params, ...args2);
    };
    };
    //I have checked it works.

  • @tdvkiran
    @tdvkiran 4 роки тому

    concept explained very clearly. Thanks :) , gotta learn alot from you

  • @sunilthind3257
    @sunilthind3257 4 роки тому +1

    Very well explained Sir... your videos are great help for learning

  • @shubhammadankar6390
    @shubhammadankar6390 2 роки тому

    Understanding it step by step- Awesome explaination

  • @akhileshpandey7044
    @akhileshpandey7044 4 роки тому

    Great actually a Best video on UA-cam please make a JavaScript whole series

  • @digvijaysingh9028
    @digvijaysingh9028 3 роки тому +8

    what a MASTERPIECE :)

  • @asimsheikh3511
    @asimsheikh3511 2 роки тому

    that was awesome. I am becoming your fan slowly. thank you for this valuable information.

  • @rabahbabaci2342
    @rabahbabaci2342 4 роки тому +3

    Thank you dude, this was an amazing explanation!
    Can you please make a video on how to implement the .call( ); method?

  • @shaikhshehroz2107
    @shaikhshehroz2107 5 років тому +3

    You are Best.. Very Well Explained.

  • @anantanujdey3642
    @anantanujdey3642 3 роки тому

    Thank You Akshay for this lovely explanation.

  • @amarnathmishra8697
    @amarnathmishra8697 2 роки тому

    one thing we missed in this series. And that is your big smile.

  • @rajendra_K_
    @rajendra_K_ 10 місяців тому

    Thank you @Akshay explaining this complex topic in a such a easy way :)

  • @atifreza3662
    @atifreza3662 3 роки тому +1

    Great content Akshay. Request you to make a video on arrow function and 'this' keyword in your Namaste JS series.

  • @premshankartiwari8613
    @premshankartiwari8613 2 роки тому

    Awesome explanation. One minor thing is missing I believe which is returning the result of the bound function.
    return obj.apply(args[0], [...params, ...args2]);

  • @harshulkansal
    @harshulkansal 3 роки тому

    Awesome work man! keep it up! really helped me through. :)

  • @yogeshbhawsar8129
    @yogeshbhawsar8129 3 роки тому

    Very nice explanation @Akshay Saini, "Ek number :-)"

  • @ram_pande8039
    @ram_pande8039 2 роки тому

    explained with simplicity. awesome content.

  • @lankanathdiaspitawalage7783
    @lankanathdiaspitawalage7783 2 роки тому

    excellent work. great teaching . I love this. Thank you

  • @itspravas
    @itspravas 5 років тому +4

    i saw your video on bind, then i saw this one, paused it, tried to do this on my own, got sucess, i haven't used call or apply or any es6 ( like "..." notation )as you said its for older browsers, so yeah i did it, really happy with my result.

    • @gopalchavan306
      @gopalchavan306 4 роки тому +1

      Hi Pravas, can you please share your code, without es6, call and apply

    • @vikramkrish710
      @vikramkrish710 4 роки тому

      Would like to see the polyfill without call and apply, how do you pass the 'this' binding inside the returning function?

  • @narendraktw
    @narendraktw 3 роки тому +1

    well explained... one thing I wanted to add if we add obj.call(...args) only then we don't need to do any other thing like param and apply... please try thanks !!!
    Function.prototype.mybind = function(...args) {
    let obj = this;
    return function (...args2){
    obj.call(...args, args2);
    }
    }
    let printName2 = fullName.mybind(name, 'Dehradun')
    printName2('Uttarakhand');

  • @dominicamaljoef6693
    @dominicamaljoef6693 4 роки тому +1

    Simple and Great Explanation Akshay :)

  • @dgroh
    @dgroh 3 роки тому

    give this guy a medal...

  • @aiswaryaroshith5383
    @aiswaryaroshith5383 6 місяців тому

    @Akshay Great explanation. Thank you. You are such a great teacher.😊

  • @patelmitulkumar5101
    @patelmitulkumar5101 2 роки тому

    Great Akshay. Awesome..
    Your explanation is very nice..

  • @TheUltimateTrainJourney
    @TheUltimateTrainJourney 4 роки тому

    It was kind of complicated but u nailed it easily 😃

  • @priteshmehetre9270
    @priteshmehetre9270 9 місяців тому

    You are a life saver for us man.......👍

  • @AIEngineering101
    @AIEngineering101 2 роки тому +2

    Thanks Akshay for explaining it clearly. I think this is the best video I watched on polyfils. I have a small question here, when we are trying to console this inside Function.prototype.myBind it is referring to window and at the same time if we assign it to variable it is referring to binding function printFullName. is this normal behaviour or am I reading it wrong?

  • @learnmore9382
    @learnmore9382 5 років тому +13

    Explained very well. Please make a video on 'this'.

    • @alexmercer416
      @alexmercer416 3 місяці тому

      after 5 yrs, ur wishes came true

  • @vanisethi2581
    @vanisethi2581 4 роки тому +1

    this is super awesome video for bind Polyfill . @akshay can you please create a polyfill video of Promise, call and apply method.

  • @NaveenRawat51
    @NaveenRawat51 5 років тому +1

    you got subscriber++. thank you Akshay the video is awesome

  • @Enjoyment1991
    @Enjoyment1991 4 роки тому +4

    Hi akshay, your teaching skills are exceptional! and can you make a video series on css? you have covered core and advanced concept of javascript likewise I need in css with building a web application from scratch

  • @himanshuaggarwal8415
    @himanshuaggarwal8415 2 роки тому

    Thanks I understand it completly.

  • @abiramimuthupandi9304
    @abiramimuthupandi9304 5 років тому +1

    It was really good! Please post videos on promises!

  • @santrawebtech35
    @santrawebtech35 2 роки тому

    you are the God of javascript bro love you

  • @TheNerdyDev
    @TheNerdyDev 5 років тому +1

    Simply Awesome.

  • @MohitKumar-tn1cf
    @MohitKumar-tn1cf 4 роки тому

    It's really good !! Can you make a video for own call method please and also have one problem in Javascript.

  • @aathig743
    @aathig743 3 роки тому

    😍😍😍 Finally We wrote own Native code. Brendan Eich i'm coming 😝.

  • @pratapdessai6687
    @pratapdessai6687 3 роки тому

    @akshay Saini Thanks for this answer. Could you add video for implementing Two way data binding .

  • @haiderimam8977
    @haiderimam8977 2 роки тому

    Wow this is one hell of an explanation.
    Love from Pakistan 🇵🇰

  • @ipsitapanda5764
    @ipsitapanda5764 3 роки тому

    Thanks for the beautiful explanation...
    @everyone :any suggestions on angular 9 learning video please

  • @anurao96
    @anurao96 2 роки тому

    Hi Akshay, If we use a Params directly in to the return function then we use obj.call(…args, …params)

  • @radhikamalpani2927
    @radhikamalpani2927 3 роки тому +6

    Please also start a playlist on Angular or React JS. I believe its going to help a lot of us. Thanks.

  • @paras981
    @paras981 4 роки тому +4

    Thank you so much for creating this video! This really helped all of us a lot! #AkshayMeraBhai

  • @muiz864
    @muiz864 5 років тому +1

    Nicely explained. Just wondering if interviewer will be okay with a polyfil for bind that uses apply internally. I mean call, bind and apply fall into a common category. Also, a browser that supports ES6 spread operator would also support bind.

  • @deekshithrajbasa
    @deekshithrajbasa 3 роки тому +3

    Well the video was great 🔥 thanks, but we are again using the apply and call function, can you do a video on how can we achieve it without using call() and apply(), thanks in advance.

  • @tejasmalani9309
    @tejasmalani9309 4 роки тому +1

    Good explaination bro ..... keep it up ! 👌

  • @vinothkumarv9722
    @vinothkumarv9722 3 роки тому

    Akshay !its really awesome bro....thanks for this.... can you explain about VIRTUAL DOM background process re consideration algorithm...how its working?...please every interview this questions coming but i was telling dont no :(

  • @DnKZone
    @DnKZone 5 днів тому

    Your this playlist is just fire

  • @imranshaikh115
    @imranshaikh115 5 років тому +1

    Good one akshay, Jhakkas

  • @codingwithgraceandtruth2456
    @codingwithgraceandtruth2456 2 роки тому

    excellent example and teaching.

  • @MyDearRishabh
    @MyDearRishabh 3 роки тому

    your explanations are simple and clear. btw, is this black t-shirt your recording uniform?

  • @syedminhaj7132
    @syedminhaj7132 3 роки тому +2

    Hi, Can you also make a video on implementing own promise and implementing own virtual DOM ? @akshay please make on async and await concepts as well.....waiting for it

  • @vishalbisht6871
    @vishalbisht6871 4 роки тому +4

    AWESOME !!!!

  • @SameeraPkChannel
    @SameeraPkChannel 3 роки тому

    Outstanding bro . Can you please make a video on polyfill for promises

  • @nitisha1492
    @nitisha1492 5 років тому +1

    Awesome as always

  • @pulkitk3388
    @pulkitk3388 5 років тому +1

    Brilliant explanation

  • @viveksai9353
    @viveksai9353 5 років тому +1

    You are like the Yoda of bind method. :-D

  • @priyasuryawanshi1143
    @priyasuryawanshi1143 3 місяці тому

    Really very good explanation

  • @varshatyagi03
    @varshatyagi03 2 роки тому

    Thanks for the explanation 😊

  • @harshapriyanknerella5770
    @harshapriyanknerella5770 3 роки тому

    It was awesome video I have learned a new concept, I have one query here.
    I tried of returning value from printName function and if we console on printMyName("India") it's showing the returned value from printName function, but when I am trying to console printMyName("India") it's returning undefined.

  • @vishalheble
    @vishalheble 4 роки тому +16

    When its a polyfill for a bind then can we really use apply or call ?

    • @patni1234561
      @patni1234561 2 роки тому +6

      This makes sense. As a interview question, it is okay, but what you said is valid. Which browser supports call apply but not bind.

  • @dodgecu
    @dodgecu 5 років тому +1

    Great, thanks!

  • @shivrajnag12
    @shivrajnag12 4 роки тому +9

    So interviewers had figured it out how to torture Frontend guys with these questions since they don't expect DS and Algo from them. Good

    • @sourav9770
      @sourav9770 3 роки тому

      lol

    • @rhimanshu6288
      @rhimanshu6288 3 роки тому

      JS is not only about frontend bro.

    • @shivrajnag12
      @shivrajnag12 3 роки тому +1

      @@rhimanshu6288 polyfills are for browsers not node environment

  • @ponmanivenkat
    @ponmanivenkat 4 роки тому

    Hi , is it possible to return those values inside the printname function instead of printing using console.log?
    if yes ,please tell how, thanks in advance

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

    well explained 👍
    ------ updated code -------
    Function.prototype.myBind = function(obj, ...arg){
    const fn = this;
    return function(){
    fn.apply(obj, arg);
    }
    }

  • @TwoTeaTee
    @TwoTeaTee 3 роки тому

    Just Wow!

  • @krishnachaitanya8088
    @krishnachaitanya8088 3 роки тому

    Thanks for the video

  • @garimabansal681
    @garimabansal681 2 роки тому

    Awesome work

  • @mipravin
    @mipravin 2 роки тому

    Hey Akshay, very nice videos. Want to ask is there any browser that does not support bind method? I mean to ask is it necessary now to have polyfill for bind.

  • @kasifmansuri7552
    @kasifmansuri7552 9 місяців тому

    Bro you are so pro.....

  • @akkiei
    @akkiei 3 роки тому

    Great video man !!

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq Рік тому

    nice great helpful

  • @Gamer-gw6nj
    @Gamer-gw6nj Рік тому

    Nice work.

  • @alwynjohn597
    @alwynjohn597 3 роки тому +1

    can you please explain how it work behind the scene when a function is returned.

  • @natasharego6033
    @natasharego6033 2 роки тому

    Hi Akshay,
    Line 17 , we could still use the call method by passing the array as elements using the spread operator , is this understanding correct?

  • @arvindbarala4525
    @arvindbarala4525 5 років тому +1

    sir please also make video for call and apply method

  • @ankitkumarvashist8991
    @ankitkumarvashist8991 3 роки тому +1

    @Akshay, that was a great explanation, Could you please bring such explanation for Polyfill for promise?

    • @akshaymarch7
      @akshaymarch7  3 роки тому

      Yup, that's a great ask. Thank you, I'll try to come up with it soon. ❤️