var f = function g(){ alert(22222)};
今天看到这段代码,虽然不这么写,但对这种形式产生了兴趣,它是怎么运行的?
测试发现,ie和火狐下还真不一样;
测试:
var f = function g(){ alert(22222)};
alert(f);
alert(f());
alert(g);
alert(g())
结果:ie:
function g(){ alert(22222)};
22222
undefined
function g(){ alert(22222)}
22222
undefined
firefox:
function g(){ alert(22222)};
22222
undefined
报错:g不存在
自己总结:ie下,相当于定义了两个变量f和g
就像:
var f = function (){ alert(22222)}
var g = function (){ alert(22222)}
firefox下:
g没有定义,什么也不是