I can explain the difference between function declarations and function expressions.
- Yes and, Function declaration has a name....where as a function expression is saved as a variable. Function declarations are hoisted, and expressions are not....the variables that are storing the functions are hoisted, but they are undefined until the variable is actually defined.
I can explain what the value of this
is in a normal function.
- It is the global object.
I can explain what the value of this
is when called from the context of an object.
- It is whatever object its being called from.
I can explain how to explicitly set the value of this
in a function.
- use
call
. Only use it to explicitly setthis
....when passing in other arguments. - use
apply
. Only use it to explicitly setthis
....when passing in other arguments when they are in an array. this
hurts my brain
I can explain the difference between call
and apply
.
- Yes, see above.
I can describe a case where I might need to use bind
to avoid polluting the global scope.
- Sortof(ish)
- We don't want to actually call that function just yet (asynch stuff happening), but we do want to explicitly set
this
.
I can explain how bind
works.
- Meh - Creates a new function where
this
has already been set