A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© sangwentao 中级黑马   /  2016-6-5 19:02  /  1712 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

js有预解析功能。就是把函数声明提前,即函数可以在定义之前使用。这个函数提前有两个特点,一个是若有多个同名函数,则使用最后一个声明的函数。第二个是预解析分标签预解析,不同标签的函数声明不会被其它标签中的代码调用。下面是示例代码:
预解析过程使函数调用最后声明的那个。
showMsg(); // This is message 2
function showMsg()
{
alert('This is message 1');
}
showMsg(); // This is message 2
function showMsg()
{
alert('This is message 2');
}

预解析是分<script>标签解析的。

<body>
<script type="text/javascript">
showMsg(); //This is message 2
function showMsg()
{
alert('This is message 1');
}
function showMsg()
{
alert('This is message 2');
}
</script>
<script type="text/javascript">
function showMsg()
{
alert('This is message 3');
}
</script>
</body>

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马