On dynamic property of JavaScript is that "eval" changes the calling context. What does it mean? Some examples would be better.
eval does change the context when called indirectly. And it changes it to the global context (the default context for all functions).
var myObj = { a: 1 }
function someFunc() {
console.log(eval('this.a')) // 1
console.log(eval('this === myObj')) // true
var indirectEval = eval
console.log(indirectEval('this.a')) // undefined
console.log(indirectEval('this === window')) // true
}
void someFunc.call(myObj)
Direct eval calls don't change the context (nor do they change the scope).
See “Global eval. What are the options?” for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With