Re:I will not do a tech interview
by tonyarkles on Wednesday August 21, 2013 @04:08PM
(#6252995)
You've never passed a callback to a JS function?
[ Parent
| on HN ]
That's an anonymous function not a closure. A closure references non-local environments and can "access those non-local variables even when invoked outside of its immediate lexical scope" as Wikipedia puts.
I don't understand your contradiction to the parent poster. All JavaScript functions are closures, including anonymous functions that don't reference any lexically-scoped variables, and even named functions at the top level, which close over the global environment[1]. Also, callback functions don't have to be anonymous functions, you can just as easily pass named functions.
1: http://javascriptweblog.wordpress.com/2010/10/25/understandi...
I know that confusing anonymous functions with closures is a common misconception. I also know that callback functions don't need to be anonymous, but a lot of the times they are, at least in the JavaScript code that I've seen.
Thank you for the clarification that all JavaScript functions are closures though.