对于下面的函数 doStuff,是否可以调用 sayHello(在函数 dostuff 之外),即使它与内部函数同名?
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();
在上面的 Javascript 代码中,函数 sayHello(这是 2 个函数的名称)是从函数内部而不是外部调用的。
这是在 jsFiddle 上:http: //jsfiddle.net/5MSTU/