In the MDN docs on block-scoped variable declarations, let
is said to not hoist. However, in babel, it seems to do just that in this example link to babel repl...
const obj = {
prop: 1,
test() {
this::log();
}
}
let log = function() { console.log(this) };
obj.test(); // logs "{ prop: 1 }" with no reference error.
Am I misunderstanding something about hoisting / the temporal deadzone?
EDIT:
Looks like this actually is not an error, as by the time obj.test()
is called, log
has been initialized, and is no longer in the temporal deadzone, therefore the reference will resolve and there will be no error. This code runs fine in chrome (46.0.2490.80
) for example...
(function() {
'use strict';
let obj = {
prop: 1,
test: function() {
log.call(this);
}
};
let log = function() {
console.log(this);
};
obj.test();
})()