Skip to content

Instantly share code, notes, and snippets.

@dlucidone
Last active February 8, 2019 04:35
Show Gist options
  • Save dlucidone/e270e9433bcd2be7598d158b8c339374 to your computer and use it in GitHub Desktop.
Save dlucidone/e270e9433bcd2be7598d158b8c339374 to your computer and use it in GitHub Desktop.
JS Bind Implementation
Function.prototype.myCall = function(){
return this.bind(...arguments)();
}
ex-
function showProfileMessage(message) {
console.log(message, this.name);
}
const obj = {
name: "Ankur Anand"
};
showProfileMessage.myCall(obj, "welcome ");
ex-
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.myCall(this, name, price);
this.category = 'food';
}
console.log(new Food('cheese', 5).name);
ex-
var sData = 'Wisen';
function display() {
console.log('sData value is %s ', this.sData);
}
display.myCall();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment