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

删除回忆录丶 提交于 2020-01-25 17:29:11

问题


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?

来源:https://stackoverflow.com/questions/3435709/why-are-functions-in-javascript-set-to-global-variables-instead-of-plain-functio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!