let as opposed to var is scoped more tightly than var but I was wondering if it changes the scoping of anonymous functions?
Example:
class Foo {
method1() {
var scopelessFunc = this.method2;
// executed in global scope
scopelessFunc();
let differentScope = this.method2;
// what scope is this executed in? (what does method2 output)
differentScope();
}
method2() {
console.log(this);
}
}
NOTE: as of today jan 14 to my knowledge let is not fully supported anywhere so I can not go and test this myself.
let
only declares where a variable will be visible. No more, no less.this
is still the global object, it has nothing to do with lexical scope.this
will depend on how you call the function.