JSFiddle - React, Tailwind, and code Playground
by vaibhav saxena
JavaScript
var employee = function(employeeId){
var details= ` EmployeeId ${employeeId} FirstName ${this.firstName} LastName ${this.lastName}`;
console.log(details);
return details;
}
var context = {
firstName: 'Peter',
lastName: 'dinklage'
};
employee.call(context, 1);
employee.apply(context, ['2'])
var empBind = employee.bind(context);
empBind(3);
Function.prototype.myCall = function(thisContext, ...args){
var s = Symbol();
thisContext[s] = this;
var output = thisContext[s](...args)
delete thisContext[s];
return output;
}
Function.prototype.myApply = function(thisContext, args =[]){
var s = Symbol();
thisContext[s] = this;
var output = thisContext[s](...args);
delete thisContext[s];
return output;
}
employee.myCall(context, '4')
employee.myCall(context, ['5'])
Function.prototype.myBind = function(thisContext, ...args) {
// Write your code here.
return (...newArgs) => this.myApply(thisContext, [...args, ...newArgs]);
};