For the function doStuff below, is it possible to call sayHello (outside the function dostuff) even though it has the same name as an inner function?
var sayHello = function(){
alert("Called from outside the function");
}
function doStuff(){
sayHello();
function sayHello(){
alert("Called from inside the function. How can I call the sayHello function that is outside the scope of doStuff?");
}
}
doStuff();
In the Javascript code above, the function sayHello (which is the name of 2 functions) is invoked from inside the function, not outside.
Here it is on jsFiddle: http://jsfiddle.net/5MSTU/
If the outer function is global, you can target it as a member of the
windowobject.Otherwise, you’ll need to use different names. JavaScript allows you to shadow variables, so an inner variable with the same name as an outer variable effectively disables access to the outer one.