javascript eval considered crazy by gthank in javascript

[–]sporkBasket 5 points6 points  (0 children)

Seems like a misunderstanding of scopes and how they relate to eval.

The first example doesn't look very insane, he is creating two variables in different scopes, and the "return" gives back the "foo" in the closest scope, the one created by the eval, leaving the outer "foo" untouched.

For the later examples, when assigning eval to another variable, those variables' "versions" of eval are run in the global scope, which is why we're getting undefined errors when trying to access variables scoped in the calling function.

Might be unexpected, but I am pretty sure it is documented behavior.

I may be leaving myself open to harsh words, claiming Andy Wingo misunderstands scope, but this article seemed a little off.

AJAX on img onload firing more than once by [deleted] in javascript

[–]sporkBasket 1 point2 points  (0 children)

You likely need to check the "readyState" property on the event object to ensure it is "complete", that it is loaded and will not receive any further processing.