Section 1

Preview this deck

constructor invocation

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (22)

Section 1

(22 cards)

constructor invocation

Front

Constructor invocation is performed when new keyword is followed by an expression that evaluates to a function object, an open parenthesis (, a comma separated list of arguments expressions and a close parenthesis ).

Back

this in a function invocation, strict mode

Front

this is undefined in a function invocation in strict mode

Back

this in a method invocation

Front

this is the object that owns the method in a method invocation

Back

Bound function

Front

A bound function is a function whose context and/or arguments are bound to specific values. You create a bound function using .bind() method. The original and bound functions share the same code and scope, but different contexts on execution.

Back

Pitfall: separating method from its object

Front

⚠️ A method can be extracted from an object into a separated variable const alone = myObj.myMethod. When the method is called alone alone(), detached from the original object, you might think that this is the object myObject on which the method was defined. 👍 Correctly if the method is called without an object, then a function invocation happens, where this is the global object window or undefined in strict mode (see 2.1 and 2.2).

Back

this inside a bound function

Front

this is the first argument of .bind() when invoking a bound function

Back

Pitfall: this in an inner function

Front

⚠️ A common trap with the function invocation is thinking that this is the same in an inner function as in the outer function. 👍Correctly the context of the inner function depends only on its invocation type, but not on the outer function's context.

Back

Invocation

Front

Invocation of a function is executing the code that makes the body of a function, or simply calling the function. For example parseInt function invocation is parseInt('15').

Back

Arrow function

Front

Arrow function is designed to declare the function in a shorter form and lexically bind the context.

Back

this in a function invocation

Front

this is the global object in a function invocation

Back

Pitfall: separating method from its object setTimout()

Front

⚠️ You might think that setTimeout(myCat.logInfo, 1000) will call the myCat.logInfo(), which should log the information about myCat object. Unfortunately the method is separated from its object when passed as a parameter: setTimout(myCat.logInfo).

Back

method invocation

Front

A method is a function stored in a property of an object

Back

this in arrow function

Front

this is the enclosing context where the arrow function is defined

Back

Conclusion

Front

Because the function invocation has the biggest impact on this, from now on do not ask yourself: Where is this taken from? but do ask yourself: How is the function invoked? For an arrow function ask yourself: What is this where the arrow function is defined? This mindset is correct when dealing with this and will save you from the headache. https://dmitripavlutin.com/gentle-explanation-of-this-in-javascript/

Back

Tight context binding

Front

.bind() makes a permanent context link and will always keep it. A bound function cannot change its linked context when using .call() or .apply() with a different context or even a rebound doesn't have any effect.

Back

this in an indirect invocation

Front

this is the first argument of .call() or .apply() in an indirect invocation

Back

this in a constructor invocation

Front

this is the newly created object in a constructor invocation

Back

Context

Front

Context of an invocation is the value of this within function body. For example the invocation of map.set('key', 'value') has the context map.

Back

function invocation

Front

Function invocation is performed when an expression that evaluates to a function object is followed by an open parenthesis (, a comma separated list of arguments expressions and a close parenthesis ). For example parseInt('18').

Back

indirect invocation

Front

Indirect invocation is performed when a function is called using myFun.call() or myFun.apply() methods.

Back

Scope

Front

Scope of a function is the set of variables, objects, functions accessible within a function body.

Back

Pitfall: forgetting about new

Front

⚠️ Using a function invocation to create objects is a potential problem (excluding factory pattern), because some constructors may omit the logic to initialize the object when new keyword is missing. 👍 Make sure to use new operator in cases when a constructor call is expected

Back