[翻译]High Performance JavaScript(009)
第三章 DOM Scripting DOM编程
DOM scripting is expensive, and it's a common performance bottleneck in rich web applications. This chapter discusses the areas of DOM scripting that can have a negative effect on an application's responsiveness and gives recommendations on how to improve response time. The three categories of problems discussed in the chapter include:
对DOM操作代价昂贵,在富网页应用中通常是一个性能瓶颈。本章讨论可能对程序响应造成负面影响的DOM编程,并给出提高响应速度的建议。本章讨论三类问题:
• Accessing and modifying DOM elements
访问和修改DOM元素
• Modifying the styles of DOM elements and causing repaints and reflows
修改DOM元素的样式,造成重绘和重新排版
• Handling user interaction through DOM events
通过DOM事件处理用户响应
But first—what is DOM and why is it slow?
但首先——什么是DOM?他为什么慢?
DOM in the Browser World 浏览器世界中的DOM
The Document Object Model (DOM) is a language-independent application interface (API) for working with XML and HTML documents. In the browser, you mostly work with HTML documents, although it's not uncommon for web applications to retrieve XML documents and use the DOM APIs to access data from those documents.
文档对象模型(DOM)是一个独立于语言的,使用XML和HTML文档操作的应用程序接口(API)。在浏览器中,主要与HTML文档打交道,在网页应用中检索XML文档也很常见。DOM APIs主要用于访问这些文档中的数据。
Even though the DOM is a language-independent API, in the browser the interface is implemented in JavaScript. Since most of the work in client-side scripting has to do with the underlying document, DOM is an important part of everyday JavaScript coding.
尽管DOM是与语言无关的API,在浏览器中的接口却是以JavaScript实现的。客户端大多数脚本程序与文档打交道,DOM就成为JavaScript代码日常行为中重要的组成部分。
 
相关文档:
判断(value)是否是一个数字,假如值是NaN那么IsNan返回TRUE,否则返回FALSE。
还有一种办法,变量可以与它自身进行比较。 假如比较的结果不等,那么它就是 NaN 。
这是因为 NaN 是唯一与自身不等的值。
第一种方法:
<html>
<head>
<title>简单计算器的制作</title>
</ ......
1.在HTML中使用<script>元素引入JavaScript。
该元素有两个属性,language声明要使用的脚本语言,src属性是可选的,用于引用外部JavaScript文件。
NB
:现在大多使用type属性(type=“text/javascript”)替代language属性,以便更好地支持XHTML(可扩展HTML)。
2.一般认为 ......
学习Javascript,最难的地方是什么?
我觉得,Object(对象)最难。因为Javascript的Object模型很独特,和其他语言都不一样,初学者不容易掌握。
下面就是我的学习笔记,希望对大家学习这个部分有所帮助。我主要参考了Object-Oriented JavaScript和Professional JavaScript for Web Developers (2nd Edition)这两本书。 ......
1.DOM是针对XML的基于树的API。使用DOM,只需解析代码一次来创建一个树的模型。在这个初始解析过程之后,XML已经完全通过DOM模型表现出来,同时也不再需要原始的代码。
NB
:DOM是语言无关的API,它并不与Java、JavaScript或其他语言绑定。 ......
Dynamic Scopes 动态作用域
Both the with statement and the catch clause of a try-catch statement, as well as a function containing eval_r(), are all considered to be dynamic scopes. A dynamic scope is one that exists only through execution of code and therefore cannot be det ......