I get confused on a JavaScript this
reference situation.
I am working on a code that I declare function inside an object method. (The reason is to tidy
this
has nothing to do with scope. It is determined by context.
greeting()
calls the function with no context, so this
is the default object (window
in a browser).
The this
, references is not related to scope, it depends on the calling context.
As per the MDN doc,
In general, the object bound to this in the current scope is determined by how the current function was called
Try person.nickname, this refers to the var greeting in your case