I can explain the difference between function declarations and function expressions. yes
I can explain what the value of this
is in a normal function.
yes
I can explain what the value of this
is when called from the context of an object.
yes
I can explain how to explicitly set the value of this
in a function.
yes
I can explain the difference between call
and apply
.
yes
I can describe an case where I might need to use bind
to avoid polluting the global scope.
Maybe
I can explain how bind
works.
Maybe. I got confused with trhe last section of the lesson. see:
Function.prototype.bindTo = function (context) {
var fn = this;
return function () {
fn.apply(context, arguments);
}
}
function logThisAndStuff(stuff) {
console.log(this, stuff);
}
var logSandwich = logThis.bindTo('sandwich');
var logTaco = logThis.bindTo('taco');
var logBurrito = logThis.bindTo('burrito');
logSandwich('one', 'two', 'three'); // 'sandwich', 'one', 'two', 'three'
logTaco('one', 'two', 'three'); // 'taco', 'one', 'two', 'three'
logBurrito('one', 'two', 'three'); // 'burrito', 'one', 'two', 'three'
All functions have access to an array-like collection called arguments. In the example above, we swap out call() for apply() and let it spread the collections of arguments passed in to our explicitly-bound function a