猿问

关于js函数的嵌套

JavaScript的函数在查找变量时从自身函数定义开始,从“内”向“外”查找。如果内部函数定义了与外部函数重名的变量,则内部函数的变量将“屏蔽”外部函数的变量。请看:

function foo(){

                var x=1;

                function bar(){

                    var x="a";

                    alert("x in bar()="+x);

                }

                alert("x in foo()="+x);

                bar();

            }

怎么理解上面的话呢?如果调用foo,县弹出x in foo()=1,后弹出x in bar()=a  这不是很正常嘛。

Drenched_belief
浏览 1766回答 1
1回答

西兰花伟大炮

弹出的顺序没问题的啊,不知道你想问什么?

慕瓜9220888

BCPVOYINQKWPREEPJTINAKXXYIPXLRBBLZTQCXLYVMDOOVWVCJHBVLPATPFZZKSPABXQKOLCRCVHXJXESRWCBRRIPXFZLMMWNKRCPOXAKBVZOJJLOFZDKHZSYRISTXIPCHANHBSICBHGHOABVGSLOOYZPHWZVYZQARKZBRXVJQGPDPYOOFCJUVENGEWNUDCBHOFZQNRJYODUZDCYJPLKUAAOQLXNGNZJQNIMVRVJAKSDCYPQKHYZFGPVTKVJJYSSSDTRVIWKJFGAARACBRJABTZPLSPWQNELYDIOEEPYWBGWVLZZGHXSIXDAIGNZHGTGHEBIHFUBWXBPCJUTZOPDTKRQJCOZMXOKZJWAPTXFAFEQQCJTJLWFBBFPQXASXDMDHINXINCIMTKKUJLUABLSFMAUJZMCZXRJGPBJGGCXFXDTNABBLTVYHISDOJDJTIZAULGLNNMQABOZDQSFFPJIUOHUWNXPBXZYXTEWJGTOTPZPGZDIMZLUZAARHWQZSZMGOIDKKDNNEYFAZZCQXKOXVXYUPPQGMHWMEEOFPFAFOYZVSTSGCSRYPZGGCZIVZZQCAEAZMGQPZKFOCVTAKOBTSLPNNYFCNUTRLIJPXIYHXKIALUJZMJHIAWWETZSWXEUNSOKJKUUFNMGSVVWJAPKQRBVIFGNIEDTWXBOGSXDJNHRYJOTQSCGAHKUXMBWMJXDIXNLFFJQXSONGZXHHMRHOEIQMQFGUNNUOOCEJVBHBFVPRCBNQXRWXQBNMCJTDKEM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