第四章 变量
1. 变量的范围 感觉这个和Java/C++的差别比较大。
(1) 首先就是没有block scope,譬如:
function test(o) {
var i = 0; // i is defined throughout function
if (typeof o == "object") {
var j = 0; // j is defined everywhere, not just block
for(var k=0; k < 10; k++) { // k is defined everywhere, not just loop
document.write(k);
}
document.write(k); // k is still defined: prints 10
}
document.write(j); // j is defined, but may not be initialized
}
下面这个例子也是同一个原理,不过更加的“不可思议”
var scope = "global";
function f( ) {
alert(scope); // Displays "undefined", not "global"
var scope = "local"; // Variable initialized here, but defined everywhere
alert(scope); // Displays "local"
}
f( );
分享到:
相关推荐
JavaScript The Definite Guide
The definite guide to Direct3D 9,随书源代码,可以参考学习。
Hadoop: the Definite guide
从sarifi离线保存打包而来,是2017年12月版本,应该很接近最后的发布版本了
The Definitive Guide to Jython, written by the official Jython team leads, covers the latest Jython 2.5 (or 2.5.x) from the basics to the advanced features. This book begins with a brief introduction ...
This is the first official book authored by the core R Markdown developers that provides a comprehensive and accurate reference to the R Markdown ecosystem. With R Markdown, you can easily create ...
The two roles have slightly different needs, but in reality, most application development covers a bit of both, so we think the material will be useful in both cases. Specifically, in our minds, the ...
XMPP 开发指南,很好的介绍文档,通俗易懂
Cassandra The Definitive Guide(2nd) 英文azw3 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
hadoop权威指南 中文版 英文版Hadoop: The Definitive Guide 带书签,无密码---抵制无良赚钱的
经典Grails书籍,针对Grails 2的升级版本,作者是: Graeme Rocher (Grails作者) Jwff Scott Brown
java 基础入门学习1-18章节,连续上传。希望对大家有帮助
IEEE 802.15.4a标准下基于半定规划算法的波形设计算法,吴宣利,孙陆宽,为了增加Zigbee的峰值数据传输速率以及拓展其应用场景,IEEE 802.15.4a标准在2007年被提出,超宽带技术也被选作它的一个物理层标准。...
广义预处理Hermitian和skew-Hermitian分裂迭代法,安静,杨爱利,对于大型稀疏非Hermitian正定线性方程组,本文在HSS迭代法的基础上,提出了一种广义的预处理Hermitian和skew-Hermitian分裂迭代法(GPHSS)。...
This report forms the user's guide for Version 4.0 of NPSOL, a set of Fortran subroutines designed to minimize a smooth function subject to constraints, which may include simple bounds on the ...
Estimation of Elgenvalues of Product of two Self-Conjugate Semi-Pdsitive Definite Quaternions Matrices (1990年)
You may have definite ideas about writing code when working alone, but team development requires that everyone use the same approach. With the JavaScript practices in this book -- including code style...
c As the response of the model in dm() is not necessarily the response of the final c model found, but rather the response of the last model tested in the univariate c optimization routines, we leave ...
第4章-简单查询 22 查询的工作原理 26 第5章-混合查询 29 混合查询 29 内部谓词 32 第6章-规则 38 规则 38 规则的工作原理 40 使用规则 45 第7章-小结 51 小结 51 第8章-算术 55 第9章-数据管理 58 第10章-递归 64 ...