Call/apply/bind

Varun Singhal
Jun 16, 2024

--

Call Method

Call is nothing just borrowing the function from other method.

let name = {
firstName:”Varun”,
lastname :”Singhal”
}

function printfull(){
console.log(this.firstName,this.lastname)
}

printfull.call(name)

//Output is Varun SInghal

If we want to extra parameter

function printfull1(place){
console.log(this.firstName,this.lastname,place)
}

printfull.call(name,”Muzaffarnagar”)

O/p — Varun singhal Muzaffarnagar

Apply —

Apply is same like call method but differnce we pass value as an Array

printfull.apply(name,[“MuzaffarNagar”])

Bind

Bind is similar to call but its give copy of function that invok latter

let b = printfull.bind(name,”Roorkee”)

b()

--

--

Varun Singhal
Varun Singhal

Written by Varun Singhal

React Native/iOS Developer (Mobile App Developer)

No responses yet