查看代码
<script type = 'text/javascript'>
function a()
{
;
}
a.prototype.hello = function()
{
alert('hello');
}
(function()
{
var b = 8;
}
());
</script>
我没有创建a的对象,也没有调用hello()函数。但是hello()被调用了。
当我移除闭包时,这个函数不会自动被调用。 即:
<script type = 'text/javascript'>
function a()
{
;
}
a.prototype.hello = function()
{
alert('hello');
}
</script>
这种奇怪行为的原因是什么?