变量预解析
var a; alert(a) 只把变量a的声明提前,赋值不提前,所以弹出undefined,表示它的值未定义
alert(c);报错,c没有声明,这是真正的未定义
函数预解析
myalert(); (弹出hello!)
function myalert(){ alert('hello!'); }
匿名函数:
有名字的函数:
window.onload = function(){
var oDiv = document.getElementById('div1');
oDiv.onclick = myalert;
function myalert(){
alert('hello'); }
匿名函数:
oDiv.onclick = function(){
alert('hello'); }
网友评论