JamesB Posted August 19, 2014 Share Posted August 19, 2014 In this thread http://w3schools.invisionzone.com/index.php?showtopic=51196 in the link he gave: http://jsfiddle.net/96eLrn6e/ He defines 2 local variables in a lambda, but then uses one of those variables outside the lambda, why does that work? I was thinking that the local variables in the lambda would be destroyed when the lambda finishes executing. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 19, 2014 Share Posted August 19, 2014 It's not using the variables defined in the onload handler, it's probably using a "feature" where the browser will use document names and IDs as global variables for those elements. It shouldn't be counted on, you should use getElementById instead. Link to comment Share on other sites More sharing options...
JamesB Posted August 19, 2014 Author Share Posted August 19, 2014 Ah thanks! had a feeling it was that. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now