`

CHAPTER 5 Statements

 
阅读更多
5.5.4 for/in

for (variable in object)
statement

for(var i = 0; i < a.length; i++) // Assign array indexes to variable i
console.log(a[i]); // Print the value of each array element

for(var p in o) // Assign property names of o to variable p
console.log(o[p]); // Print the value of each property

5.7.1 with

with (object)
statement

in non-strict mode: avoid using it whenever possible

document.forms[0].address.value

with(document.forms[0]) {
// Access form elements directly here. For example:
name.value = "";
address.value = "";
email.value = "";
}

避免使用with语句,你可以使用下面的方法:
var f = document.forms[0];
f.name.value = "";
f.address.value = "";
f.email.value = "";

范围链只是用来查找标识的,而不是创建新的的,考虑下面的语句:
with(o) x = 1;
如果o有一个x属性,那么这个属性将赋值1.如果没有的话,那么不会给o创建一个x属性,x相当于在with语句的外面,可能会创建一个本地或者全局的属性。
分享到:
评论

相关推荐

    JavaScript权威指南(第6版)

    Chapter 5 Statements Chapter 6 Objects Chapter 7 Arrays Chapter 8 Functions Chapter 9 Classes and Modules Chapter 10 Pattern Matching with Regular Expressions Chapter 11 JavaScript Subsets and ...

    JavaScript权威指南(第6版).JavaScript:The.Definitive.Guide

    Chapter 5 Statements Chapter 6 Objects Chapter 7 Arrays Chapter 8 Functions Chapter 9 Classes and Modules Chapter 10 Pattern Matching with Regular Expressions Chapter 11 JavaScript Subsets and ...

    Chapter 13 SQL Statement Syntax.pdf

    5. **删除表语法**: - 用于删除现有表。 - 语法示例: `DROP TABLE table_name;` 6. **创建和删除索引语法**: - 用于在表上创建或删除索引。 - 创建索引的语法示例: `CREATE INDEX index_name ON table_name ...

    02 - Financial Statements, Cash Flow, and Taxes

    ### 金融报表、现金流与税收 #### 一、引言 在投资领域,尤其是在寻找具有增长潜力的投资标的时,理解并分析企业的财务状况至关重要。彼得·林奇(Peter Lynch),这位曾管理过价值100亿美元的富达麦哲伦基金...

    Java.7.A.Comprehensive.Tutorial

    Chapter 3 Statements Chapter 4 Objects and Classes Chapter 5 Core Classes Chapter 6 Inheritance Chapter 7 Error Handling Chapter 8 Numbers and Dates Chapter 9 Interfaces and Abstract Classes Chapter ...

    Object Pascal Handbook,最新Ddelphi书籍,for XE7

    Chapter 5: Arrays and Records Chapter 6: All About Strings Part II Chapter 7: Objects Chapter 8: Inheritance Chapter 9: Handling Exceptions Chapter 10: Properties and Events Chapter 11: Interfaces ...

    Learn.C++.Programming.Language.Become.A.Complete.C++.Programmer.pdf

    Chapter 5. A Tour of C++: Concurrency and Utilities Part II: Basic Facilities Chapter 6. Types and Declarations Chapter 7. Pointers, Arrays, and References Chapter 8. Structures, Unions, and ...

    C.in.a.Nutshell.2nd.Edition.1491904755

    Chapter 5. Expressions and Operators Chapter 6. Statements Chapter 7. Functions Chapter 8. Arrays Chapter 9. Pointers Chapter 10. Structures and Unions and Bit-Fields Chapter 11. Declarations Chapter ...

    Speaking JavaScript

    Chapter 5. Standardization: ECMAScript Chapter 6. Historical JavaScript Milestones Part III: JavaScript in Depth Chapter 7. JavaScript’s Syntax Chapter 8. Values Chapter 9. Operators Chapter 10. ...

    Applied ADO.NET: Building Data-Driven Solutions(2)

    Chapter 5 - Handling ADO.NET Events Chapter 6 - Integrating XML with ADO.NET Chapter 7 - Data Binding and Windows Forms Data-Bound Controls Chapter 8 - Constraints and Data Relations Chapter ...

    JavaScript 圣经第5版-Javascript编程宝典--黄金版 .rar

    Chapter 42: Global Functions and Statements. Part V: Putting JavaScript to Work. Chapter 43: Data-Entry Validation. Chapter 44: Scripting Java Applets and Plug-ins. Chapter 45: Debugging Scripts. ...

    iOS.10.in.Swift.3.epub

    Chapter 8: Boolean Logic & Conditional Statements Chapter 9: Math Operators Chapter 10: Classes Chapter 11: Inheritance Chapter 12: Polymorphism Chapter 13: About Version Control Chapter 14: Git ...

    Cplusplus.Language.Tutorial.For.Beginner.Learn.Cplusplus.in.7.days

    Chapter 5. Arrays, Pointers, and References Chapter 6. Classes Chapter 7. Overloading Chapter 8. Derived Classes Chapter 9. Templates Chapter 10. Exception Handling Chapter 11. The IO Library Chapter ...

    PHP.7.Object-Oriented.Modular.Programming.B01E

    There are quite a number of ...Chapter 5: Handling and Logging Exceptions Chapter 6: Data Objects Chapter 7: Authentication Chapter 8: Multifunctional Interfaces

Global site tag (gtag.js) - Google Analytics