Polyfill for bind method | Javascript Interview Questions

Поделиться
HTML-код
  • Опубликовано: 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 года назад +149

    @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

  • @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,

  • @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.

  • @kirank3368
    @kirank3368 4 года назад +4

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

  • @mohityadav21
    @mohityadav21 2 года назад +7

    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.

  • @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.

  • @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

  • @sumitjangir48
    @sumitjangir48 4 года назад +7

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

  • @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" 😎

  • @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.

  • @shadahmedmasthikund8965
    @shadahmedmasthikund8965 4 месяца назад

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

  • @shubhammadankar6390
    @shubhammadankar6390 2 года назад

    Understanding it step by step- Awesome explaination

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

    Thank You Akshay for this lovely explanation.

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

    give this guy a medal...

  • @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.

  • @ram_pande8039
    @ram_pande8039 2 года назад

    explained with simplicity. awesome content.

  • @digvijaysingh9028
    @digvijaysingh9028 3 года назад +8

    what a MASTERPIECE :)

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

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

  • @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

  • @shaikhshehroz2107
    @shaikhshehroz2107 5 лет назад +3

    You are Best.. Very Well Explained.

  • @priteshmehetre9270
    @priteshmehetre9270 9 месяцев назад

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

  • @pintzprajapati
    @pintzprajapati 2 года назад

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

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

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

  • @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

  • @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);
    }

  • @DnKZone
    @DnKZone 4 дня назад

    Your this playlist is just fire

  • @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?

  • @TheNerdyDev
    @TheNerdyDev 5 лет назад +1

    Simply Awesome.

  • @himanshuaggarwal8415
    @himanshuaggarwal8415 2 года назад

    Thanks I understand it completly.

  • @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.

  • @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.

  • @santrawebtech35
    @santrawebtech35 2 года назад

    you are the God of javascript bro love you

  • @amarnathmishra8697
    @amarnathmishra8697 2 года назад

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

  • @TheUltimateTrainJourney
    @TheUltimateTrainJourney 4 года назад

    It was kind of complicated but u nailed it easily 😃

  • @mohammedg485
    @mohammedg485 2 года назад

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

  • @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 :)

  • @abhishek8330
    @abhishek8330 Год назад

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

  • @codingwithgraceandtruth2456
    @codingwithgraceandtruth2456 2 года назад

    excellent example and teaching.

  • @pulkitk3388
    @pulkitk3388 5 лет назад +1

    Brilliant explanation

  • @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?

  • @akhileshpandey7044
    @akhileshpandey7044 4 года назад

    Great actually a Best video on RUclips please make a JavaScript whole series

  • @varshatyagi03
    @varshatyagi03 2 года назад

    Thanks for the explanation 😊

  • @aiswaryaroshith5383
    @aiswaryaroshith5383 6 месяцев назад

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

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

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

  • @rajendra_K_
    @rajendra_K_ 10 месяцев назад

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

  • @dodgecu
    @dodgecu 5 лет назад +1

    Great, thanks!

  • @haiderimam8977
    @haiderimam8977 2 года назад

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

  • @patelmitulkumar5101
    @patelmitulkumar5101 2 года назад

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

  • @learnmore9382
    @learnmore9382 5 лет назад +13

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

    • @alexmercer416
      @alexmercer416 3 месяца назад

      after 5 yrs, ur wishes came true

  • @vishalbisht6871
    @vishalbisht6871 4 года назад +4

    AWESOME !!!!

  • @NaveenRawat51
    @NaveenRawat51 5 лет назад +1

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

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

    Thanks for the video

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

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

  • @priyasuryawanshi1143
    @priyasuryawanshi1143 2 месяца назад

    Really very good explanation

  • @asimsheikh3511
    @asimsheikh3511 2 года назад

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

  • @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]);

  • @tejasmalani9309
    @tejasmalani9309 4 года назад +1

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

  • @nitisha1492
    @nitisha1492 5 лет назад +1

    Awesome as always

  • @abiramimuthupandi9304
    @abiramimuthupandi9304 5 лет назад +1

    It was really good! Please post videos on promises!

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

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

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

    Just Wow!

  • @kasifmansuri7552
    @kasifmansuri7552 9 месяцев назад

    Bro you are so pro.....

  • @garimabansal681
    @garimabansal681 2 года назад

    Awesome work

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

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

  • @jatinnandwani6678
    @jatinnandwani6678 Год назад

    Thanks so much

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq Год назад

    nice great helpful

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

    Great video man !!

  • @Gamer-gw6nj
    @Gamer-gw6nj Год назад

    Nice work.

  • @anurao96
    @anurao96 2 года назад

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

  • @hadeedtmgggg5837
    @hadeedtmgggg5837 Год назад

    Thanks sir❣️❣️❣️

  • @viveksai9353
    @viveksai9353 5 лет назад +1

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

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

    Nice explanation

  • @imranshaikh115
    @imranshaikh115 5 лет назад +1

    Good one akshay, Jhakkas

  • @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.

  • @paras981
    @paras981 4 года назад +4

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

  • @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.

  • @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.

  • @abhishekjha831
    @abhishekjha831 2 года назад

    pura hindi jaisa lagta h..nice

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

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

  • @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.

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

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

  • @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?

  • @yogeshvitkar1943
    @yogeshvitkar1943 2 года назад

    Superb

  • @manojrathore8727
    @manojrathore8727 5 месяцев назад

    O bhayankar, dehradun se. 😂😂 great tutorial

  • @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.

  • @blessingseverywhere7774
    @blessingseverywhere7774 5 лет назад +1

    u r awesome

  • @SarathBabuN
    @SarathBabuN 5 лет назад +1

    Really very nice video

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

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

  • @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

  • @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

  • @MrVisheshsingh
    @MrVisheshsingh 4 года назад +1

    Wow 😍

  • @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 :(

  • @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.