Why are functions in JavaScript set to global variables instead of plain functions?

I am wondering if anyone knows why some people define global variables that are set to functions vs just defining a global function name. For example:

var foo = function() { alert('hello!'); }

instead of

function foo() { alert('hello!'); }

Wouldn't the second method be better since there is a chance something might overwrite the first variable and you would lose the function? Does this have anything to do with extending objects? Are there performance concerns?

链接地址: http://www.djcxy.com/p/344.html

上一篇: 我如何在JavaScript中声明一个名称空间?

下一篇: 为什么JavaScript中的函数设置为全局变量而不是普通函数?