Call Site
This is the part 2 of the series on this keyword in Javascript.
Call-Site : location where a function is called( not where it’s declared). Finding call site in plain JS code is simple but certain coding pattern can hide the true call-site.
For understanding this, we need to find the call-site before the currently executing function.
function findCallSite() {//call-stack is : findCallSite//our call-site is in global scopeconsole.log("Inside findCallSite");getToCallSite();}function getToCallSite() {//call-stack is findCallSite-> getToCallSite//so our callSite is findCallSiteconsole.log("Inside getToCallSite");getToSecondCallSite();}function getToSecondCallSite() {//call-stack is findCallSite-> getToCallSite->getToSecondCallSite//so our callSite is getToCallSiteconsole.log("Inside getToSecondCallSite");}findCallSite(); // call-site for findCallSite
Debugger in visual studio code will show call stack as below
Use the below link to visualise the call stack of the above code.
Determining the rule for “this binding” will be covered in next part of the series.
Default Binding:
Implicit Binding:
Explicit Binding:
new Binding:
Binding Order:
Navigate to part 1 of the series with below link where this keyword is explained briefly: —