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
@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
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,
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.
You are simply awesome 👏🏽 The way you clear things and make us understand it very straight is fabulousness. Thanks bro 🙏
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.
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.
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
Bro.. You are doing social service for us... Thanks for your help.. Keep helping.. keep growing...
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" 😎
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.
The best teacher I've ever got for how to learn and what to learn in java script... Akshay sir❤
Understanding it step by step- Awesome explaination
Thank You Akshay for this lovely explanation.
give this guy a medal...
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.
explained with simplicity. awesome content.
what a MASTERPIECE :)
Really impressive way of teaching and the topics/questions are superb.
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
You are Best.. Very Well Explained.
You are a life saver for us man.......👍
Learned first time and wow it was super easy because of your teaching method. thanks bro
Excellent explanation. Akshay bro u are fav teacher of mine..
concept explained very clearly. Thanks :) , gotta learn alot from you
Very well explained Sir... your videos are great help for learning
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);
}
Your this playlist is just fire
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?
Simply Awesome.
Thanks I understand it completly.
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.
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.
you are the God of javascript bro love you
one thing we missed in this series. And that is your big smile.
It was kind of complicated but u nailed it easily 😃
I'm glad i found your channel, its gold. keep it up brother.
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 :)
well explained 👍
------ updated code -------
Function.prototype.myBind = function(obj, ...arg){
const fn = this;
return function(){
fn.apply(obj, arg);
}
}
excellent example and teaching.
Brilliant explanation
Thank you dude, this was an amazing explanation!
Can you please make a video on how to implement the .call( ); method?
Great actually a Best video on RUclips please make a JavaScript whole series
Thanks for the explanation 😊
@Akshay Great explanation. Thank you. You are such a great teacher.😊
Very nice explanation @Akshay Saini, "Ek number :-)"
Thank you @Akshay explaining this complex topic in a such a easy way :)
Great, thanks!
Wow this is one hell of an explanation.
Love from Pakistan 🇵🇰
Great Akshay. Awesome..
Your explanation is very nice..
Explained very well. Please make a video on 'this'.
after 5 yrs, ur wishes came true
AWESOME !!!!
you got subscriber++. thank you Akshay the video is awesome
Thanks for the video
😍😍😍 Finally We wrote own Native code. Brendan Eich i'm coming 😝.
Really very good explanation
that was awesome. I am becoming your fan slowly. thank you for this valuable information.
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]);
Good explaination bro ..... keep it up ! 👌
Awesome as always
It was really good! Please post videos on promises!
Awesome work man! keep it up! really helped me through. :)
Just Wow!
Bro you are so pro.....
Awesome work
Great content Akshay. Request you to make a video on arrow function and 'this' keyword in your Namaste JS series.
Thanks so much
nice great helpful
Great video man !!
Nice work.
Hi Akshay, If we use a Params directly in to the return function then we use obj.call(…args, …params)
Thanks sir❣️❣️❣️
You are like the Yoda of bind method. :-D
Nice explanation
Good one akshay, Jhakkas
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.
Thank you so much for creating this video! This really helped all of us a lot! #AkshayMeraBhai
It's really good !! Can you make a video for own call method please and also have one problem in Javascript.
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.
pura hindi jaisa lagta h..nice
Thanks for the beautiful explanation...
@everyone :any suggestions on angular 9 learning video please
this is super awesome video for bind Polyfill . @akshay can you please create a polyfill video of Promise, call and apply method.
@akshay Saini Thanks for this answer. Could you add video for implementing Two way data binding .
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?
Superb
O bhayankar, dehradun se. 😂😂 great tutorial
Please also start a playlist on Angular or React JS. I believe its going to help a lot of us. Thanks.
u r awesome
Really very nice video
Thanks Sarath 😊
Outstanding bro . Can you please make a video on polyfill for promises
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
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
Wow 😍
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 :(
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.