call,

Function.prototype.myCall = function(currentContext = {}, ...arg) {

if (typeof this !== 'function') {
throw new Error(this + "it's not callable");
}
currentContext.fn = this;
currentContext.fn(...arg);

};

apply,

Function.prototype.myApply = function(currentContext = {}, arg = []) {
if (typeof this !== 'function') {
throw new Error(this + "it's not callable");
}
if (!Array.isArray(arg)) {
throw new TypeError('called on non-object')
}
currentContext.fn = this;
currentContext.fn(...arg);

};

bind,

Function.prototype.myBind = function(currentContext = {}, ...arg) {

if (typeof this !== 'function') {
throw new Error(this + "cannot be bound as it's not callable");
}
currentContext.fn = this;

return function () {
return currentContext.fn(...arg);
};
};

I know there would always be something to improve. Please feel free to share your thoughts

--

--

Sonika | Working at Walmart | startlearncoding.com

Sonika | Working at Walmart | startlearncoding.com

Working in Walmart as Senior UI Developer | React | JavaScript | Data Structure