Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有以下代码:
var stop = false if (!$(this).val()) { stop = true }
'stop = true' 声明是否将变量作为全局变量传回,或者只是更改它的值 - 或全新的东西!
stop = true在这种情况下,将更改变量的值。
stop = true
请记住功能范围。如果var在函数内使用,则声明的变量将不在全局范围内。
var
例如,如果你有这个:
var stop = false; function foo() { var stop = true; }
调用foo()不会改变stop. 现在有一个局部stop的和一个全局的stop。然而...
foo()
stop
var stop = false; function foo() { stop = true; }
现在,当调用 时foo(),stop它的值将会改变。