And because the global object does not know anything about say() function, 'this' is undefined.
Should be something like this instead...
And because the global object does not have a caller property, this.caller is undefined.
In the explanation for example 2:
(if you're using a browser console, you might see "null" (Firefox) or "[url referring to the window object]"(Chrome) instead of "undefined")
I tested in Chrome and Firefox and I get undefined in both browsers. This makes sense, because in these examples this.caller is equivalent to window.caller, which is undefined (unless some code on the current page has set this property).
Thank you, James! Yes. That makes much more sense. I was googling around trying to find the simplest explainer, only to complicate my own thought process. Really appreciate your input :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Annie, a couple of small corrections...
In the explanation for examples 2 and 3:
Should be something like this instead...
In the explanation for example 2:
I tested in Chrome and Firefox and I get
undefined
in both browsers. This makes sense, because in these examplesthis.caller
is equivalent towindow.caller
, which isundefined
(unless some code on the current page has set this property).Thank you, James! Yes. That makes much more sense. I was googling around trying to find the simplest explainer, only to complicate my own thought process. Really appreciate your input :)