Created
July 26, 2020 13:28
-
-
Save sudikrt/89aa5f45aa3c1e69f636978ff3a604f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function () { | |
console.log (`${this.firstName} - ${this.lastName}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (name) | |
printMyName(); | |
console.log ('Function proto starts'); | |
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function () { | |
console.log (`${this.firstName} - ${this.lastName}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (nameObj) | |
printMyName(); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
return function() { | |
self.call (args[0]); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj); | |
myPrint2(); | |
//belwo will not take extra params | |
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function (home) { | |
console.log (`${this.firstName} - ${this.lastName}-${home}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (nameObj, 'myhome') | |
printMyName(); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
return function() { | |
self.call (args[0]); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj, 'myhome'); | |
myPrint2(); | |
//end | |
//Extra Params | |
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function (home) { | |
console.log (`${this.firstName} - ${this.lastName}-${home}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (name, 'myhome') | |
printMyName(); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
let params = args.splice (1); | |
return function() { | |
self.call (args[0], params); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj, 'myhome'); | |
myPrint2(); | |
//Stril more params will n't support | |
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function (home, state) { | |
console.log (`${this.firstName} - ${this.lastName}-${home} - ${state}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (name, 'myhome') | |
printMyName('tState'); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
let params = args.splice (1); | |
return function() { | |
self.call (args[0], params); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj, 'myhome'); | |
myPrint2('tshit'); | |
//end | |
et nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function (home, state) { | |
console.log (`${this.firstName} - ${this.lastName}-${home} - ${state}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (name, 'myhome') | |
printMyName('tState'); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
let params = args.splice (1); | |
return function(...arg2) { | |
self.call (args[0], [...params, ...args]); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj, 'myhome'); | |
myPrint2('tshit'); | |
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function (home, state) { | |
console.log (`${this.firstName} - ${this.lastName}-${home} - ${state}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (name, 'myhome') | |
printMyName('tState'); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
let params = args.splice (1); | |
return function(...arg2) { | |
self.call (args[0], [...params, ...arg2]); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj, 'myhome'); | |
myPrint2('tshit'); | |
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function (home, state, country) { | |
console.log (`${this.firstName} - ${this.lastName}-${home} - ${state} - ${country}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (name, 'myhome') | |
printMyName('tState', 'In'); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
let params = args.splice (1); | |
return function(...arg2) { | |
self.call (args[0], [...params, ...arg2]); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj, 'myhome'); | |
myPrint2('tshit', 'In'); | |
//more params any where | |
let nameObj = { | |
firstName : 'SK', | |
lastName : 'cool' | |
} | |
let printName = function (home, state, country) { | |
console.log (`${this.firstName} - ${this.lastName}-${home} - ${state} - ${country}`); | |
} | |
//task is to create own implementatio of bind | |
let printMyName = printName.bind (name, 'myhome', 'tState', 'In') | |
printMyName(); | |
console.log ('Function proto starts') | |
Function.prototype.myBind = function (...args) { | |
let self = this; | |
let params = args.splice (1); | |
return function(...arg2) { | |
self.call (args[0], [...params, ...arg2]); | |
} | |
} | |
let myPrint2 = printName.myBind (nameObj, 'myhome', 'tState', 'In'); | |
myPrint2(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment