Function Junction Flashcards

1
Q

Short def. of a closure

A

Function that returns references to objects from its local scope.
- Typically returns an IIF

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

T/F: A method’s context (this) is bound to the object that it is a method of

A

False. A calling function can give ‘function context’ to a method.

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

Another name for ‘context’ in javascript

A

“This” = context

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

How is ‘this’ defined in strict mode?

A

Strict mode requires an assigned context, or ‘this’ is undefined. It does not default to global object.

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

Function w/ Call – what’s happening?

myFunction.call(x, 1,2)

A

myFunction will be executed with the properties of ‘x’ and other given parameters

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

Function w/ Apply – what’s happening?

myFunction.apply(x, [1,2])

A

this = ‘x’ and the rest of the parameters are given in an array
* Use if the other parameters you wanted to send were already in an array?

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

What is the syntax diff between declaring a function and invoking a function?

A

Declaration: uses function keyword to define a function

Invoking: uses ( ); and returns a value

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

What is a function expression? Why is this a significant distinction?

A

A function assigned to a variable, not defined with formal function definition.
+ Allows reassignment of variable
+ Assigned function can be anonymous
+ Function expressions are not hoisted b/c they follow variable scope rules

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

How do you invoke an anonymous function?

A

Assign to variable (create function expression) and call with variable name
- End with semi-colon to execute

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

Syntax for a self-invoking function

A

Entire function wrapped in ( ),followed by ( );
* Cannot be used on function declaration

(function( ){ …stuff…})( );

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