I am trying to understand why object destructuring is changing the scope?
(function() {
var o = {
add: function(a , b) {
return a + b;
},
log: function () {
console.log(this);
}
}
var { log } = o;
o.log();
log();
})();
this code will log two different objects
the first one is object o as expected but the second will log the global object
UPDATE (3 - May - 2021): If you have the same question and looking for a more detailed answer, read this one as well: How does the "this" keyword work?