I read in Java also that anonymous functions introduces a new scope within the enclosing function whereas lambda expressions are block-local.Does it mean the above.I am confused with the following example:
var timer = {
seconds: 0,
start() {
setInterval(() => {
this.seconds++
}, 1000)
}
}
// When an item is searched, it starts from the anonymous function
// and this doesn't mean the same as parent this.
// This means that we can access this .seconds by first going to
// its enclosing function in the arrow expression.
timer.start()
setTimeout(function () {
console.log(timer.seconds)
}, 3500)
Here this.seconds will introduce a new scope of this in the enclosing function if it is an anonymous function.Am I right? Static (Lexical) Scoping vs Dynamic Scoping (Pseudocode)