[size=medium]
If global variables are properties of the special global object, then what are local variables? They too are
properties of an object. This object is known as the call object . The call object has a shorter lifespan than
the global object, but it serves the same purpose. While the body of a function is executing, the function
arguments and local variables are stored as properties of this call object. The use of an entirely separate
object for local variables is what allows JavaScript to keep local variables from overwriting the value of
global variables with the same name.
[/size]
If global variables are properties of the special global object, then what are local variables? They too are
properties of an object. This object is known as the call object . The call object has a shorter lifespan than
the global object, but it serves the same purpose. While the body of a function is executing, the function
arguments and local variables are stored as properties of this call object. The use of an entirely separate
object for local variables is what allows JavaScript to keep local variables from overwriting the value of
global variables with the same name.
[/size]
本文探讨了JavaScript中局部变量的本质及其存储方式。通过使用独立的调用对象来存储函数参数及局部变量,JavaScript能够避免局部变量覆盖同名的全局变量,确保了变量作用域的清晰界定。
4230

被折叠的 条评论
为什么被折叠?



