【发布时间】:2012-01-24 18:53:18
【问题描述】:
所以我听说在没有“var”的情况下初始化的 js 中的变量将是全局的。所以:
$(document).ready(function(){
function foo(){
//since i'm not using "var", will this function become global?
}
var bar = function(){
//is this the better way to declare the function?
}
})
如果它是全局的,为什么我不能在控制台中访问它。如果它不是全局的,并且它的作用域在函数中,那么省略“var”会花费一些性能吗?谢谢。
【问题讨论】: