Polyfill in Javascript | Polyfill for call apply and bind | Javascript Interview Questions

preview_player
Показать описание
Hey everyone, I have started a new polyfill series. These polyfills are asked in frontend interviews. I will be covering polyfills from basic to advanced. This video is on polyfill for call, apply and bind 😱.

So Stay tuned! And do watch this video till the end 🙏

Subscribe here 🤗 -

Timestamps -
0:00 Introduction
0:25 Need for call, apply and bind explained
1:30 Call Polyfill
9:30 Apply Polyfill
12:35 Bind Polyfill

Link to other videos 📚
Polyfill for filter and reduce -
Polyfill for map and foreach -
Frontend Interview Experience -
Frontend System Design 🧑‍💻 -
MMT Interview -
Top DSA Questions -

#reactjs #javascript #frontend
Рекомендации по теме
Комментарии
Автор

Hey lovelies 💜, thank you for watching.
Don't forget to like, share and subscribe 🤗
Also do comment if you like the video 🖐

akashingole
Автор

Thanks @akashingole . You made it sooo simple and easy. your polyfill series series like a hidden gem. Thanks again best wishes to you : D

healthyliving
Автор

Great video bro, keep doing videos like this.
One small thing you missed is that you are adding a function to the object but not deleting it. Make sure to remove function from the object after the function call is done

randomcodmobile
Автор

very helpfull content, One place for all polyfill questions. thankyou Akash.
for apply, this code is working fine with list of array

Function.prototype.myApply = function (obj = {}, args) {
if (typeof this !== "function") {
throw new Error("Not callable");
}
if (!Array.isArray(args)) {
throw new called on non-object");
}
obj.fn = this;
obj.fn(...args);
};


please let know if its helpfull

AkashYadav-lvzh
Автор

If we implement polyfill of call, it will attach fn to the person1 object, so we need to delete that property manually after calling that function
delete obj.fn

tarun_sahnan
Автор

bind never takes argument when we are binding it, it takes arguments while executing it then why are we taking 'args1' ?

megatron
Автор

bhai tu apni ads thodinkm 1 video mei 20 sec ki
5 add aati hai

nitinchugh
Автор

Bro please correct me if I am wrong, but the polyfill for apply is not correct, cause in obj.fn(...args), in this ...args will give an array, and thus, if you run this code for more than arguments passed in array for myapply method then it will treat the whole ...args in obj.fn(...args), as one argument and thus treat it same way, I am attaching my code please see it, and if I am making some mistake please correct me.

let obj1 = {
name: 'Name1'
}

let obj2 = {
name: "Name2"
}

function printInfo(age, year) {
console.log(`He is ${this.name} and he is ${age}, and ${year} born`)
}

Function.prototype.myApply = function(obj = {}, ...args) { // we should use args here instead of ...args, all other things will work
if(typeof this !== 'function') throw new Error('Not Applyable')

if(!Array.isArray(...args)) throw new Error('TypeError: CreateListFromArrayLike called on non-object')

console.log(' ...args', ...args); // this will print [28, 1995]
obj.fn = this;
obj.fn(...args);
}

printInfo.apply(obj2, [28, 1995]); // it will print: "He is name2 and he is 28, and 1995 born"
printInfo.myApply(obj1, [28, 1995]); // it will print: "He is name1 and he is 28, 1995, and undefined born"

kunarkkhewal
welcome to shbcf.ru