Closures • An expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression). • This generally happens when a function contains another function inside it, and has access to the outer function's variables. If the outer function returns and the inner function is still accessible to outside code, the inner function still has access to the outer function's variables. • This can result in security issues in some cases, but also has some practical applications.
Closure Example The function getSecret() is declared within Guard(), which returns a reference to function getSecret(). This gives outside code access to an internal function, in turn giving the outside code access to the variables used within the inner function which, in this case, belong to function Guard(). Output (Along with a blank page):
Window Creation/Manipulation Code See? Easy.
Rollover Illustrated The buttons darken as the mouse rolls over them, this helps to show users which objects are clickable and/or lead to links. Button A will link to http://www.google.com and Button 2 will link to http://www.yahoo.com.