[翻译]High Performance JavaScript(005)
第二章 Data Access 数据访问
One of the classic computer science problems is determining where data should be stored for optimal reading and writing. Where data is stored is related to how quickly it can be retrieved during code execution. This problem in JavaScript is somewhat simplified because of the small number of options for data storage. Similar to other languages, though, where data is stored can greatly affect how quickly it can be accessed later. There are four basic places from which data can be accessed in JavaScript:
经典计算机科学的一个问题是确定数据应当存放在什么地方,以实现最佳的读写效率。数据存储在哪里,关系到代码运行期间数据被检索到的速度。在JavaScript中,此问题相对简单,因为数据存储只有少量方式可供选择。正如其他语言那样,数据存储位置关系到访问速度。在JavaScript中有四种基本的数据访问位置:
Literal values 直接量
Any value that represents just itself and isn't stored in a particular location. JavaScript can represent strings, numbers, Booleans, objects, arrays, functions, regular expressions, and the special values null and undefined as literals.
直接量仅仅代表自己,而不存储于特定位置。 JavaScript的直接量包括:字符串,数字,布尔值,对象,数组,函数,正则表达式,具有特殊意义的空值,以及未定义。
Variables 变量
Any developer-defined location for storing data created by using the var keyword.
开发人员使用var关键字创建用于存储数据值。
Array items 数组项
A numerically indexed location within a JavaScript Array object.
具有数字索引,存储一个JavaScript数组对象。
Object members 对象成员
A string-indexed location within a JavaScript object.
具有字符串索引,存储一个JavaScript对象。
Each of these data storage locations has a particular cost associated with reading and writing operations involving the data. In most cases, the performance difference between accessing information from a literal value versus a local variable is trivial. Accessing info
相关文档:
上面所说有关HTML的内容非常少又简单,但对已经了解的人来说就是没用的.
如有问题可到权威网 http://www.html.com/ 上查看
以下开始说说关于XML的一些知识.
XML也是标记语言,可它是自定义的,没有已给定格式.不具体说它,给出例子就可明了.
如
<NAME>TOM</NAME>
<SEX>M</SEX>
以上内容的< ......
看书的时候遇到这样一个问题,程序代码如下
var ob = function(){
var obj = this;
function fn1(){
alert( obj === window );//false
alert( this === window );//ture
}
this.fn2 = function() {
fn1();
}
}
当时很不明白fn1里面第二个alert的结果,为 ......
<SCRIPT>
//判断y年的农历中那个月是闰月,不是闰月返回0
function leapMonth(y){
return(lunarInfo[y-1900]&0xf);
}
var lunarInfo=new Array(
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0 ......
从这篇起,会由浅到深的分析js OO之写类方式,大概会有5-8篇。后面陆续会分析流行库(框架)的写类方式。为了讨论的单一性,暂不考虑类的继承,(私有,受保护)属性或方法。
EMCA262规范中没有类(class)的概念,js的new只是让他看起来更像c++,java一点。这里说的写类,只是书写js代码风格而已。
1、构造函数方式
/**
* P ......
<script language='javascript'>
function toggleAll(cb)
{
var val = cb.checked;
var frm = document.forms[0];
var len = frm.elements.length;
var i=0;
for( i=0 ; i<len ; i++)
&nb ......