`

《Javascript -- The Definite Guide》第四章笔记

阅读更多

第四章  变量

 

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( );

 

 

 

分享到:
评论

相关推荐

    The definite guide to Direct3D 9随书源代码

    The definite guide to Direct3D 9,随书源代码,可以参考学习。

    Spark The Definitive Guide-201712

    《Spark The Definitive Guide-201712》是大数据处理领域中一本非常重要的参考资料,由知名数据工程师及作者Bill Karwin 和 Databricks 的团队共同编写。这本书全面覆盖了Apache Spark的核心概念、技术和最佳实践,...

    The R Series - R Markdown The Definitive Guide (2018)

    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 Definitive Guide to Jython-Python for the Java Platform

    ### 关于《The Definitive Guide to Jython—Python for the Java Platform》的知识点解析 #### 一、Jython简介 Jython 是一种开放源代码的实现方式,它将 Python 这种高级、动态且面向对象的脚本语言无缝集成到 ...

    Automotive Ethernet - The Definitive Guide

    4. **车载以太网架构**:车载以太网通常采用星型、环形或混合拓扑结构,每个节点通过物理层(PHY)连接到网络。网络管理、故障检测和安全性是架构设计的关键考虑因素。 5. **安全性与隐私**:车载以太网必须具备...

    Cassandra The Definitive Guide(2nd) azw3

    Cassandra The Definitive Guide(2nd) 英文azw3 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    ch02-primitive-data-definite-loops.pdf

    这份文件是一份标题为“ch02-primitive-data-definite-loops.pdf”的文档的内容摘要,摘自《Building Java Programs》书籍的第2章,具体讲的是Java基础入门的1-18章节。文档中提到了Java的数据类型,包括原始数据...

    hadoop权威指南 中文版 英文版Hadoop: The Definitive Guide 带书签,无密码

    4. 探索Hadoop与其他大数据技术的整合,增强数据分析能力。 5. 熟悉Hadoop的数据输入输出方式,优化数据处理效率。 总的来说,《Hadoop权威指南》是一本全面而深入的Hadoop学习资料,无论你是想要入门前沿的大数据...

    On generalized preconditioned Hermitian and skew-Hermitian splitting methods for non-Hermitian positive definite linear systems

    广义预处理Hermitian和skew-Hermitian分裂迭代法,安静,杨爱利,对于大型稀疏非Hermitian正定线性方程组,本文在HSS迭代法的基础上,提出了一种广义的预处理Hermitian和skew-Hermitian分裂迭代法(GPHSS)。...

    User's Guide for NPSOL

    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 ...

    occam一维反演

    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 ...

    Matrix Not Positive Definite(解决方案).md

    项目中碰到的问题

    Gauss-Seidel-Method.zip_To the Letter

    Though it can be applied to any matrix with non-zero elements on the diagonals, convergence is only guaranteed if the matrix is either diagonally dominant, or symmetric and positive definite....

    Indefinite and Definite Integrals.zip

    同时,双语字幕文件"Matlab Training - 57 - Indefinite and Definite Integrals - 英语 (自动生成) 中文(简体)(双语).srt"可以帮助中英文用户更好地理解和学习,无论是初学者还是有经验的MATLAB用户,都能从中...

Global site tag (gtag.js) - Google Analytics