可能重复:
使用var和不使用JavaScript中的var之间的区别
我应该使用window.variable还是var?
我已经看到了两种在javascript中声明类的方法.
喜欢
window.ABC = ....
Run Code Online (Sandbox Code Playgroud)
要么
var ABC = ....
Run Code Online (Sandbox Code Playgroud)
使用类/变量有什么区别吗?
Ale*_*pin 11
var为当前范围创建变量.因此,如果您在函数中执行此操作,则无法在其外部访问它.
function foo() {
var a = "bar";
window.b = "bar";
}
foo();
alert(typeof a); //undefined
alert(typeof b); //string
alert(this == window); //true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17424 次 |
| 最近记录: |