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
@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 ?
medium pe bass gyaan milta hai.. real life scenario nhi milne wale..
akshay bhai k liye meri taraf se 2 likes
@@pioneer7161 bhai 2 likes mat kar ek hi kar 2 karega toh jo ek kiya woh Bhi hat jayega😜😜
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
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.
Your explanation about basic concepts is so good. I've been watching the entire JS series! Thank you so much
You are simply awesome 👏🏽 The way you clear things and make us understand it very straight is fabulousness. Thanks bro 🙏
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.
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" 😎
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.
How does this variable refer printName method inside myBind function? I am confused here.
6:37 nee,
Bro.. You are doing social service for us... Thanks for your help.. Keep helping.. keep growing...
I can clearly see closure application in poly filling the bind function. 😅 Thanks for providing this power to see through code, Akshay.
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
The best teacher I've ever got for how to learn and what to learn in java script... Akshay sir❤
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
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.
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.
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.
Really impressive way of teaching and the topics/questions are superb.
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);
}
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.
Learned first time and wow it was super easy because of your teaching method. thanks bro
I'm glad i found your channel, its gold. keep it up brother.
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.
Excellent explanation. Akshay bro u are fav teacher of mine..
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.
concept explained very clearly. Thanks :) , gotta learn alot from you
Very well explained Sir... your videos are great help for learning
Understanding it step by step- Awesome explaination
Great actually a Best video on UA-cam please make a JavaScript whole series
what a MASTERPIECE :)
that was awesome. I am becoming your fan slowly. thank you for this valuable information.
Thank you dude, this was an amazing explanation!
Can you please make a video on how to implement the .call( ); method?
You are Best.. Very Well Explained.
Thank You Akshay for this lovely explanation.
one thing we missed in this series. And that is your big smile.
Thank you @Akshay explaining this complex topic in a such a easy way :)
Great content Akshay. Request you to make a video on arrow function and 'this' keyword in your Namaste JS series.
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]);
Awesome work man! keep it up! really helped me through. :)
Very nice explanation @Akshay Saini, "Ek number :-)"
explained with simplicity. awesome content.
excellent work. great teaching . I love this. Thank you
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.
Hi Pravas, can you please share your code, without es6, call and apply
Would like to see the polyfill without call and apply, how do you pass the 'this' binding inside the returning function?
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');
Simple and Great Explanation Akshay :)
give this guy a medal...
@Akshay Great explanation. Thank you. You are such a great teacher.😊
Great Akshay. Awesome..
Your explanation is very nice..
It was kind of complicated but u nailed it easily 😃
You are a life saver for us man.......👍
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?
Explained very well. Please make a video on 'this'.
after 5 yrs, ur wishes came true
this is super awesome video for bind Polyfill . @akshay can you please create a polyfill video of Promise, call and apply method.
you got subscriber++. thank you Akshay the video is awesome
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
Thanks I understand it completly.
It was really good! Please post videos on promises!
you are the God of javascript bro love you
Simply Awesome.
It's really good !! Can you make a video for own call method please and also have one problem in Javascript.
😍😍😍 Finally We wrote own Native code. Brendan Eich i'm coming 😝.
@akshay Saini Thanks for this answer. Could you add video for implementing Two way data binding .
Wow this is one hell of an explanation.
Love from Pakistan 🇵🇰
Thanks for the beautiful explanation...
@everyone :any suggestions on angular 9 learning video please
Hi Akshay, If we use a Params directly in to the return function then we use obj.call(…args, …params)
Please also start a playlist on Angular or React JS. I believe its going to help a lot of us. Thanks.
Thank you so much for creating this video! This really helped all of us a lot! #AkshayMeraBhai
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.
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.
Good explaination bro ..... keep it up ! 👌
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 :(
Your this playlist is just fire
Good one akshay, Jhakkas
excellent example and teaching.
your explanations are simple and clear. btw, is this black t-shirt your recording uniform?
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
AWESOME !!!!
Outstanding bro . Can you please make a video on polyfill for promises
Awesome as always
Brilliant explanation
You are like the Yoda of bind method. :-D
Really very good explanation
Thanks for the explanation 😊
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.
When its a polyfill for a bind then can we really use apply or call ?
This makes sense. As a interview question, it is okay, but what you said is valid. Which browser supports call apply but not bind.
Great, thanks!
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
lol
JS is not only about frontend bro.
@@rhimanshu6288 polyfills are for browsers not node environment
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
well explained 👍
------ updated code -------
Function.prototype.myBind = function(obj, ...arg){
const fn = this;
return function(){
fn.apply(obj, arg);
}
}
Just Wow!
Thanks for the video
Awesome work
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.
Bro you are so pro.....
Great video man !!
nice great helpful
Nice work.
can you please explain how it work behind the scene when a function is returned.
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?
sir please also make video for call and apply method
@Akshay, that was a great explanation, Could you please bring such explanation for Polyfill for promise?
Yup, that's a great ask. Thank you, I'll try to come up with it soon. ❤️