With JavasScript, say there is an innerFunction()
defined within an outerFunction()
. If you attempt to call the innerFunction()
, outside of the outerFunction()
, there will be an error as it is not defined within the scope.
However, if while in the outerFunction()
, you assign the innerFunction()
to an event, say a click event, for some outside element, like a button
, then the innerFunction()
can be called from that scope of the button, whatever it may be. So why are you able to make this second call to innerFunction()
froma different scope.
I have a working example: http://jsfiddle.net/rcmoore38/gPrMk/
The initial changeColor()
call does not work, but when changeColor()
is assigned to the button
, it can be called via the button.
Thank you!