this and obj prototype Flashcards

1
Q

‘this’ keyword definition

A

It’s special identifier keyword that’s automatically defined in the scope of every function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

the “WHY” of ‘this’

A

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’})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Does ‘this’ points to the function object?

A

False it does not! It’s a totally different identifier than the function object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Does ‘this’ somehow refers to the function’s scope?

A

No, it does not refer in any way to the function’s scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Does ‘this’ has author-time binding or run-time binding?

A

‘this’ has run-time binding, which means that the meaning of the ‘this’ identifier is decided on how a function is invoked

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a call-site for a function?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly