Skip to content

Instantly share code, notes, and snippets.

@tarunranka
Created May 11, 2019 07:27
Show Gist options
  • Save tarunranka/8d2f02c132a5d4e679ee34eab8c9bc65 to your computer and use it in GitHub Desktop.
Save tarunranka/8d2f02c132a5d4e679ee34eab8c9bc65 to your computer and use it in GitHub Desktop.
let person = {
firstName:"Tarun",
lastName:"Ranka"
}
const printFullName = function(newHown,state,country){
console.log(`${this.firstName} ${this.lastName} ${newHown} ${state} ${country}`);
}
const callFn = printFullName.bind(person);
// callFn();
Function.prototype.myBind= function(...args){
let self = this;
let [obj, ... params] = args;
return function(...arg){
// console.log(arg);
self.apply(obj,[...params,...arg]);
}
}
const newFn = printFullName.myBind(person,'Chennai');
newFn('Tamil Nadu','India');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment