作者:LAMP小白 点击:2157 发布日期:2013-01-03 11:31:00 返回列表
对于所有变量,无论是在函数体的何处声明,都会在后台被提升到函数顶部
但是这里有个有趣的例子,有一个函数其中有haha hehe两个函数,但是局部函数haha()的定义被提升到了顶部并能正常运行,但hehe()的定义
并没有提升,只有声明被提升到了顶部,阻止了全局函数hehe(),但其自身无法运行
mio_lt;scriptmio_gt; function haha() { alert('global haha'); } function hehe() { alert('global hehe'); } function a() { console.log(typeof haha); //function console.log(typeof hehe); //undifined function haha() { alert('local haha'); } var hehe = function(){ alert('local hehe'); } } a(); mio_lt;/scriptmio_gt;
上一篇:js回调模式 下一篇:快递查询API