I can explain the difference between function declarations and function expressions.
- function expressions are defined by
var name = ...are invoked withname(...)but are not hoisted. - function declarations are defined by
function name(...){...}, are invoked similarly, and are hoisted.
Rules for this:
-
thisis the global object (window, or global when in terminal)
-
thisis whatever object the function/method is being called from
-
thisis whatever you say this is.
I can explain what the value of this is in a normal function.
thisis the window itself.
I can explain what the value of this is when called from the context of an object.
thisis the object.
I can explain how to explicitly set the value of this in a function.
- the call method executes a function, but the first parameter is the new
this.
I can explain the difference between call and apply.
- the apply method and call method are identical, except, call takes 2nd - nth parameter as parameters, while call takes these parameters as an array.
- note... in ruby you can use splat for this kind of thing. arry = [1,2,3], def method(x,y,z) x + y + z end, method(*arry) works. In ES6, method(...arry) also works.
I can describe an case where I might need to use bind to avoid polluting the global scope.
I can explain how bind works.
- calling bind on a function returns a brand new function, where the first param to bind sets
thisin new function, the latter params do partial function application.