I am reading Effective JavaScript. In chapter 2, Item 17: Prefer Indirect eval to Direct eval, there is the following:
"The eval function has a secret weapon: It's more than just a function. Most functions have access to the scope where they are defined, and nothing else. But eval has access to the full scope at the point where it's called. This is such immense power that when compiler writers first tried to optimize JavaScript, they discovered that eval made it difficult to make any function calls efficient, since every function call needed to make its scope available at runtime in case the function turned out to be eval
From what I understand, calling eval directly gives access to the local scope of the caller.
var x = "global";
function test() {
var x = "local";
return eval("x");
}
test(); // "local"
In the example above, eval has access to the local scope of the caller.
What does this have to do with the bold highlighted part of the passage I quoted from the book? I didn't understand exactly what was meant. Can someone provide a more thorough explanation of how functions make their scope available at runtime? I realize I'm being a bit vague in my question, but it's because I didn't really get the quoted passage at all. Also, how is this related to "direct eval costs dearly in performance"?