js语法作用域之间的相关性

mac2022-06-30  24

语法作用域的级别为:

相同级别的语法作用域可以相互的嵌套,例如 1 function foo1{ 2 function foo2(){ 3 function foo3(){ 4 5 } 6 } 7 } View Code 高级别的雨打作用域能够包含低级别的语法作用域,例如我们常用的如下例子 1 function foo(){ 2 //...... 3 if(true){ 4 //..... 5 } 6 } View Code 低级别的语法作用域不能包含高级别的语法作用域例如 1 my_label:{ 2 function foo(flag){ 3 while(flag){ 4 break my_label; 5 } 6 } 7 } 8 alert(‘out of my_label’); 9 foo(); View Code 在该例子中会提示标签找不到,这意味着my_label不在函数foo()可见的语法作用域内,这是因为标签低于函数作用域,这段代码和下面的代码为等价的 1 my_label:{ 2 //..... 3 } 4 function foo(){ 5 while(tag){ 6 break my_label; 7 } 8 } 9 foo(); View Code

 

转载于:https://www.cnblogs.com/programerlrc/archive/2013/06/02/3113990.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)