功能:
重新加载文档。
语法:
location.reload(force)
参数:
force:可选参数,是一个布尔值。
如果省略参数,或者参数是false,它就会用HTTP头If-Modified-Since来检测服务器上的文档是否已改变。如果文档已改
变,reload()会再次下载该文档。如果文档未改变,则该方法将从缓存中装载文档。这与用户单击浏览器的刷新按钮的效果是完全一样的。
如果把参数设置为true,那么无论文档的最后修改日期是什么,它都会绕过缓存,从服务器上重新下载该文档。这与用户在单击浏览器的刷新按钮时按住
Shift 健的效果是完全一样。 ......
1.浮点运算
这可能是挫败一些对javascript不熟悉并准备执行一些数学运算的人的主要原
因.
<script>
alert(0.02 / 0.1); //0.19999999999999998
alert(1.14 * 100); //113.99999999999999 ;)
</script>
Math.round()
就能在这里派上用场.
2.加号操作符的重载
"+"加号运算符即能做算术运算,又能够做字
符串的连接.如果正确的使用它是很便利的.让我们看一看.
<script>
var
msg, one=
"1"
;
msg = 2 + "1"
;
// msg = "21"
msg = 2 + one; // msg = "21"
msg = 1 + 1 + 1 + " musketeers"
;
// msg = "3 musketeers"
msg = "Bond "
+ 0  ......
Identifier Resolution Performance 标识符识别性能
Identifier resolution isn't free, as in fact no computer operation really is without some sort of performance overhead. The deeper into the execution context's scope chain an identifier exists, the slower it is to access for both reads and writes. Consequently, local variables are always the fastest to access inside of a function, whereas global variables will generally be the slowest (optimizing JavaScript engines are capable of tuning this in certain situations). Keep in mind that global variables always exist in the last variable object of the execution context's scope chain, so they are always the furthest away to resolve. Figures 2-4 and 2-5 show the speed of identifier resolution based on their depth in the scope chain. A depth of 1 indicates a local variable.
标识符识别不是免费的,事实上没有哪种电脑操作可以不产生性能开销。在运行期上下文的作用域链中,一个标识符所处的位置越深,它的读写速 ......
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 determined simply by static analysis (looking at the code structure). For example:
无论是with表达式还是try-catch表达式的catch子句,以及包含eval_r()的函数,都被认为是动态作用域。一个动态作用域只因代码运行而存在,因此无法通过静态分析(察看代码结构)来确定(是否存在动态作用域)。例如:
function execute(code) {
eval_r(code);
function subroutine(){
return window;
}
var w = subroutine();
//what value is w?
};
The execute() function represents a dynamic scope due to the use of eval_r(). The value of w can change based on the value of code. In most cases, w will be equal to the global window object, bu ......
Nested Members 嵌套成员
Since object members may contain other members, it's not uncommon to see patterns such as window.location.href in JavaScript code. These nested members cause the JavaScript engine to go through the object member resolution process each time a dot is encountered. Figure 2-12 shows the relationship between object member depth and time to access.
由于对象成员可能包含其它成员,例如不太常见的写法window.location.href这种模式。每遇到一个点号,JavaScript引擎就要在对象成员上执行一次解析过程。图2-12显示出对象成员深度与访问时间的关系。
Figure 2-12. Access time related to property depth
图2-12 访问时间与属性深度的关系
It should come as no surprise, then, that the deeper the nested member, the slower the data is accessed. Evaluating location.href is always faster than window.location.href, which is faster than window.location.href.toString(). If these properties aren't on the object instances, then mem ......
第三章 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 浏览器世界中的D ......