Polyfill for bind
this example shows polyfill for bind
by DineshAngappa
JavaScript
let user = {
firstName: 'John',
lastName: 'Smith'
};
let printFullName = function(city, hometown) {
console.log(this.firstName +" " + this.lastName + " "+ city + " "+ hometown);
}
let name = printFullName.bind(user, 'coimbatore');
name('madurai');
Function.prototype.myBind = function(...args) {
let self = this,
params = args.slice(1);
return function(...args2) {
self.apply(args[0], [...params, ...args2])
}
}
let name1 = printFullName.myBind(user, 'mumbai');
console.log(name1('delhi'));