call, apply & bind
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
Këto tre metoda vendosin se çfarë është this brenda një funksioni. call() dhe apply() e thërrasin menjëherë; bind() kthen një funksion të ri me this të fiksuar — i dobishëm për event handler-a.
EnglishEN
These three methods set what this is inside a function. call() and apply() call it immediately; bind() returns a new function with this fixed — handy for event handlers.
Si ta mendosh
Si t'i thuash një aktori cilin personazh të luajë.
Lexoje në anglisht
Like telling an actor which character to play.
Shembull kodijavascript
function pershendet() { return "Tung, " + this.emri; }
const arta = { emri: "Arta" };
pershendet.call(arta); // "Tung, Arta"
const fiks = pershendet.bind(arta);