this and obj prototype Flashcards
‘this’ keyword definition
It’s special identifier keyword that’s automatically defined in the scope of every function
the “WHY” of ‘this’
using ‘this’ inside function leads to a cleared API: for example it’s possible to create a function that doesn’t need to explicitly refer to a passed context but instead refer to the implicit identifier ‘this’, automatically created in its scope.
Instead of doing this:
function identify(context) { return context.name.toUpperCase(); }
on could write the function in this way:
function identify() { return this.name.toUpperCase(); }
and invoke it like this:
identify.call({ name: ‘Stefano’})
Does ‘this’ points to the function object?
False it does not! It’s a totally different identifier than the function object
Does ‘this’ somehow refers to the function’s scope?
No, it does not refer in any way to the function’s scope
Does ‘this’ has author-time binding or run-time binding?
‘this’ has run-time binding, which means that the meaning of the ‘this’ identifier is decided on how a function is invoked
What is a call-site for a function?
It’s basically where it is being executed in relation to the current call stack. If we have only one single function being executed then the call-site is the global context, otherwise it’s the function context in which our specific function is being called