第1章

Page_24-Line_7 :

Basically, the method works by walking the DOM document tree looking for a specific className and an optional node and tag filter; it retrieves all the DOM elements associated with the specified class, node, and tag. Take the following document for example:

[原译文——意译]
从本质上说,这个方法的工作原理是根据可选的节点和标签在DOM文档树中查找类属性包含className的元素,最终取得的DOM元素都与指定的类、节点和标签相关。以下面的文档为例:

[编辑修改的结果——现在书中文字]
从本质上说,这个方法的工作原理是在DOM文档树中查找类属性包含某个className、可选的节点和标签过滤器的元素,找出所有与指定的类、节点和标签相关的DOM元素。以下面的文档为例:

[现译文——直译]
从本质上说,这个方法的工作原理是对DOM文档树进行遍历,从中查找特定的className、可选的节点和标签筛选器;最终取得所有与特定的类、节点和标签相关的DOM元素。以下面的文档为例:

Page_28-文字第三段:

“……,因为换行符将被解释为分号(;)。”中的分号应该是英文分号,即:(;)。

 Page_32-图1-4上方第二段:

“打开本书源文件中的chapter/……”,应该是“……chapter1/……”。

 Page_42-文字第一段:

“……注册了window的load事件侦听器:” ,修改为“……为window注册了load事件侦听器:”比较好理解。

Page_43-倒数第二段:

“本章也介绍了在使用JavaScript这门语言的过程可能会遇到的许多常见的陷阱。”应该是:
“本章也介绍了在使用JavaScript这门语言的过程中,可能会遇到的许多常见陷阱。”

Page_64-代码:
initPage 应该是
function initPage

豪情

朋友们的留言

  1. soni | 08月 9th, 2008 at 09:48

    第2章有一个很严重的错误,作为译者不应该看不出来。
    2.1.1继承
    这里讲了一个很不恰当的例子,明显是一个错误的例子。
    employee.getName = person.getName;
    这个显然不能叫做继承方法,而且根本就不是继承,只不过是指向了同一个匿名函数。
    原书英文版我没见过,但这明显不是翻译的问题,作者如果连这个问题都搞错,恐怕不是粗心的问题了。
    另外,抛开前文,图2.1也是那么的别扭。

    Reply to this comment
  2. 5study | 09月 17th, 2008 at 17:00

    刚拿到书,还在看,发现会来提交,作者很认真,感谢!

    Reply to this comment
  3. admin | 09月 17th, 2008 at 20:53

    @soni

    抱歉,这么长时间没有回复你的问题。其实,这本书作者对什么是继承非常清楚,而且,作者在书中也提到“在JavaScript中,继承是通过简单地从一个对象原型向另一个对象原型复制对象而实现的,但最终的思想都是相同的”。而且,那个例子和图用来说明作者描述的继承也是完全没有问题的。

    只不过,每个人心目中对继承这个概念的理解可能有所差异。请恕我直言,这本书没有讲述一般入门级的内容,而且关于继承也就讲了这么一小部分,应该说揭示出了继承的实质。

    Reply to this comment
  4. admin | 09月 17th, 2008 at 20:55

    @5study

    在审读这本书中文版的过程中,我和朋友也发现了一些错误和问题。抽时间我会及时补充这个勘误页面。多谢支持!

    Reply to this comment
  5. soni | 10月 7th, 2008 at 17:10

    多谢你的解答。

    仔细看了一下那段文字,作者确实只说了employee继承了person中的方法,而没有说employee继承了person。

    本例中,如果person添加了新的属性,那么employee不会自动获取这个新属性。所以,按照传统的继承概念来说,employee和person肯定不是继承和被继承关系。

    Reply to this comment
  6. 琳琳的小狗 | 11月 7th, 2008 at 16:47

    @soni

    其实这种做法应该叫做mixin……

    Reply to this comment
  7. solar | 01月 12th, 2009 at 13:27

    function $(){
    var elecment = new Array();
    for (var i=0;i

    Reply to this comment
  8. chirsjie | 07月 28th, 2009 at 09:15

    买了这本书了,确实很不错.
    不过有些内容还是不太理解,例如在构建自己的库那段,有这样的写法,
    window['ads']['method'] = …..

    这个是关联数组? 它可以等于这样的形式吗?看的很迷惑
    window.ads.method

    麻烦您有时间给讲解一下 谢谢

    Reply to this comment
    • 为之漫笔 | 07月 28th, 2009 at 10:31

      在JavaScript中,访问对象属性的方式有两种:一种是关联数组方式,即你列举的第一种方式;另一种就是点记号法,即你列举的第二种方式。

      在内部实现中,JavaScript对象就是关联数组;这种实现的价值在于,可以在程序运行中动态访问对象属性,例如:window[someProperty]中的someProperty可以是任意字符串,但不同的字符串可以访问window的不同属性。

      Reply to this comment
  9. chirsjie | 07月 28th, 2009 at 13:21

    回复的很及时,感谢,

    Reply to this comment
  10. 大爷 | 09月 1st, 2009 at 13:46

    你真丑!

    Reply to this comment
  11. duanhun87 | 07月 10th, 2010 at 13:39

    书的后面部分比较难懂,特别是一些案例!

    Reply to this comment
  12. duanhun87 | 07月 10th, 2010 at 14:45

    7.2.2章的那个案例,模拟XMLHttpRequest对象,看得不大懂,因为没有PHP基础。
    php那一段的原理实在不太懂。而且不明白所谓“回调函数”是什么意思。
    案例中发送的
    this.url=……?XSS_HTTP_REQUEST_CALLBACK=this.requestID_CALLBACK
    是否就是让服务器调用Window.XSS_HTTP_REQUEST_1_CALLBACK函数?

    如果是,为何文中说:“响应将会作为脚本被载入,而且返回的函数也将被执行:XSS_HTTP_REQUEST_1({message:’It Worked’})”

    而不是XSS_HTTP_REQUEST_1_CALLBACK({message:’It Worked’})?这个CALLBACK到底怎么回事?
    哎都怪我没有PHP基础

    Reply to this comment
  13. hezc | 10月 29th, 2010 at 10:44

    javascript DOM高级程序设计 什么时候可以再版。
    现在市场上都没得卖了。

    Reply to this comment
  14. 为之漫笔 | 10月 29th, 2010 at 10:53

    @hezc

    到淘宝或者孔夫子(http://www.kongfz.com/)去看看?

    Reply to this comment
  15. 豪情 | 01月 3rd, 2011 at 22:02

    我又发现一下,64页。
    initPage(){}
    应该为function initPage(){}吧。

    Reply to this comment
  16. 为之漫笔 | 01月 4th, 2011 at 18:27

    @豪情 多谢,是的。

    Reply to this comment
  17. stone crusher | 01月 8th, 2011 at 10:22

    博主很细心

    Reply to this comment
  18. robinhu | 01月 31st, 2011 at 02:07

    一:
    1.3.7 – 作用域解析与闭包
    作者多次提到“作用域链”是函数执行时所处的位置决定的,其实应为函数定义时所处位置决定的。
    比如:
    31页末尾到32页初的一句话(当引用一个变量或方法时,JavaScript会沿着由对象执行路径构成的作用域链对作用域进行解析,查找变量最近定义的值,一旦找到,即使用该值。)
    再比如:
    34页图1-7所示以及对应代码(拷贝自source文件):
    function registerListener(anchor,myNum) {
    ADS.addEvent(anchor, ‘click’, function() {
    alert(‘My id is anchor’ + myNum + ‘ and initAnchors i is ‘ + i);
    });
    }

    function initAnchors() {
    for ( i=1 ; i<=5 ; i++ ) {
    var anchor = document.getElementById('anchor'+i);
    registerListener(anchor,i);
    }
    }

    ADS.addEvent(window, 'load', initAnchors);

    加上34页最初的话:……,因此最终还是要从initAnchors()函数的作用域中取得i的值,……
    其实应该注意到for循环里面的i没有使用var声明,所以i便成为了window的成员,所以图1-7最左边的节点应该为"window"而不是"initAnchors()",因此作者想通过这个例子证明:是不可行的。
    P.S.:其实57页中讲到“特权方法”时,作者应该知道;但107页最后一句话:“而且,使用call()也能够防止对递归函数的作用域进行意外操作”,其实即使有意也根本不可能进行任何操作,除非用户自定义函数定义在walkTheDOMRecursive函数中,这又让我感觉作者认为,因为第三章还没看完,所以不确定后面又会怎样,纠结中……

    二:
    myLogger.js文件(书中75页)
    myLogger.prototype.write函数的定义中:
    ……
    if(typeof message != ‘string’) {
    if(message.toString) return this.writeRaw(message.toString());
    else return this.writeRaw(typeof message);
    }
    ……
    感觉改为下面的更为妥当:
    ……
    if(typeof message != ‘string’) {
    if(message && message.toString) return this.writeRaw(message.toString());
    else return this.writeRaw(typeof message);
    }
    ……
    因为当调用write函数时未向其中添加参数或参数值为null时(即message的值为undefined或null),将会导致异常.

    三:
    72页倒数第四行
    else if(typeof li.innerHTML != undefined)
    应为:
    else if(typeof li.innerHTML != ‘undefined’)
    同理74页中间代码:
    if(typeof li.innerHTML != undefined)
    应为:
    if(typeof li.innerHTML != ‘undefined’)
    同样情况没有仔细检查,可能还有。

    四:
    59页中间
    原文:同样地,记住以下几条规则可以保证你对所有成员的身份作出适当地界定。
    Also, keeping the following rules in mind will ensure you define things properly:
    应译为:
    同样地,记住以下几条规则可以保证你对所有成员恰当地进行定义。

    同页译注2以及要解释的句子对应的翻译认为有误:
    Static members apply only to a particular instance of an object.
    应为:
    “静态成员只适用于某一个特定的实例对象”或“只把静态成员应用于某一个特定的实例对象”.(译注应为:即同一个构造函数用“new”关键字产生的所有实例中的某个个别实例)

    Reply to this comment
  19. robinhu | 01月 31st, 2011 at 02:15

    忘说了:是本好书,翻译的也挺好,译注也很到位。
    刚才用了大于号和小于号导致不完全,补上:

    加上34页最初的话:……,因此最终还是要从initAnchors()函数的作用域中取得i的值,……
    其实应该注意到for循环里面的i没有使用var声明,所以i便成为了window的成员,所以图1-7最左边的节点应该为”window”而不是”initAnchors()”,因此作者想通过这个例子证明:”‘作用域链’是函数执行时所处的位置决定的”是不可行的。
    P.S.:其实57页中讲到“特权方法”时,作者应该知道”‘作用域链’是函数定义时所处位置决定的”;但107页最后一句话:“而且,使用call()也能够防止对递归函数的作用域进行意外操作”,其实即使有意也根本不可能进行任何操作,除非用户自定义函数定义在walkTheDOMRecursive函数中,这又让我感觉作者认为”‘作用域链’是函数执行时所处的位置决定的”,因为第三章还没看完,所以不确定后面又会怎样,纠结中……

    Reply to this comment
  20. robinhu | 01月 31st, 2011 at 03:19

    又忘说了,个人愚见,说错了请博主见谅啊,呵呵。另请问博主知不知道英文版的勘误表在哪下?我只找到了提交错误的地方。。。

    Reply to this comment
  21. robinhu | 02月 6th, 2011 at 02:56

    35页
    本页多次提到的getElementsByTagName()返回的是NamedNodeMap对象,而实际上返回的应该是NodeList对象。
    参考:
    http://www.w3school.com.cn/xmldom/met_element_getelementsbytagname.asp
    http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614

    代码实验:
    ADS.addEvent(window, ‘load’, function() {
    var all = document.getElementsByTagName(‘*’);
    for(var i in all) {
    alert(i);
    }
    });
    结果:
    1.firefox(3.6.13):
    (一系列数字)/length/item/namedItem
    2.IE(8.0)
    length/(一系列数字夹杂页面中的一系列元素id值)
    3.Opera(11.01)
    (一系列数字)/length/item/namedItem
    4.Safari(5.0.3)
    (一系列数字)/length/item
    5.Chrome(9.0.591.84)
    (一系列数字)/length/item

    可以看出firefox以及Opera可能返回的是扩展之后的NodeList或是一个HTMLCollection对象,如果是后者的话那就不符合规范了吧。
    参考:
    http://www.w3school.com.cn/xmldom/dom_htmlcollection.asp
    其中这句话解释了区别:
    HTMLCollection 对象和 NodeList 对象很相似,但前者可能既能用名称索引也能用数字索引。

    况且NamedNodeMap对象确实有一个getNamedItem()方法,但没有namedItem()方法(HTMLCollection对象里倒是有),且如果用for..in语句的话,应该有更多方法名显示才对。
    参考:
    http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1780488922
    http://www.w3school.com.cn/xmldom/dom_namednodemap.asp

    另外请教博主:
    http://www.w3school.com.cn/xmldom/dom_node.asp

    http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247
    中对Node对象的描述(或定义)中attributes属性一个有一个没有,难道是w3school少写了?

    Reply to this comment
  22. robinhu | 02月 6th, 2011 at 17:05

    怪事,昨天提交的,今天就不见了,而且再次提交的话显示“检测到重复评论”。。。
    35页
    本页多次提到的getElementsByTagName()返回的是NamedNodeMap对象,而实际上返回的应该是NodeList对象。
    参考:
    http://www.w3school.com.cn/xmldom/met_element_getelementsbytagname.asp
    http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614

    代码实验:
    ADS.addEvent(window, ‘load’, function() {
    var all = document.getElementsByTagName(‘*’);
    for(var i in all) {
    alert(i);
    }
    });
    结果:
    1.firefox(3.6.13):
    (一系列数字)/length/item/namedItem
    2.IE(8.0)
    length/(一系列数字夹杂页面中的一系列元素id值)
    3.Opera(11.01)
    (一系列数字)/length/item/namedItem
    4.Safari(5.0.3)
    (一系列数字)/length/item
    5.Chrome(9.0.591.84)
    (一系列数字)/length/item

    可以看出firefox以及Opera可能返回的是扩展之后的NodeList或是一个HTMLCollection对象,如果是后者的话那就不符合规范了吧。
    参考:
    http://www.w3school.com.cn/xmldom/dom_htmlcollection.asp
    其中这句话解释了区别:
    HTMLCollection 对象和 NodeList 对象很相似,但前者可能既能用名称索引也能用数字索引。

    况且NamedNodeMap对象确实有一个getNamedItem()方法,但没有namedItem()方法(HTMLCollection对象里倒是有),且如果用for..in语句的话,应该有更多方法名显示才对。
    参考:
    http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1780488922
    http://www.w3school.com.cn/xmldom/dom_namednodemap.asp

    另外请教博主:
    http://www.w3school.com.cn/xmldom/dom_node.asp

    http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247
    中对Node对象的描述(或定义)中attributes属性一个有一个没有,难道是w3school少写了?

    Reply to this comment
  23. Genaro Matkin | 09月 15th, 2011 at 23:23

    You’ve some genuinely beneficial information composed here. Great job and keep posting good stuff.

    Reply to this comment
  24. cigarette starter kits | 09月 16th, 2011 at 02:47

    Respect to the post author. This is really some wonderful information.

    Reply to this comment
  25. Ugg Boots On Sale | 10月 7th, 2011 at 12:06

    Ugg Boots On Sale I really like this website, and hope you will write more ,thanks a lot for your information.
    http://www.bestuggaustralia.com

    Reply to this comment
  26. nfl jerseys | 10月 7th, 2011 at 12:07

    Nfl Jerseys,The article is worth reading, I like it very much. I will keep your new articles.
    http://www.nfljerseysmalls.com

    Reply to this comment
  27. north face outlet | 11月 5th, 2011 at 15:33

    Old Farmer Johnson was dying. The family was standing around his bed. With a low voice he said to his wife: “When I’m dead I want you to marry farmer Jones.”
    Wife: “No, I can’t marry anyone after you.”
    Johnson: “But I want you to.”
    Wife: “But why?”
    Johnson: “Jones once cheated me in a horse deal!”

    Reply to this comment
  28. leather jacket | 11月 22nd, 2011 at 13:04

    Resources like the one you mentioned here will be very useful to me! The information mentioned in the article are some of the best available.

    Reply to this comment
  29. moncler jackets women sale | 11月 24th, 2011 at 14:40

    With the coat and boots Ugg 5815, to the clear fall day brought the slightest warmth.

    Reply to this comment
  30. discount new era hats | 12月 7th, 2011 at 15:16

    http://www.newerahatfactory.com/ Wangjiangmin life did not attend college, 38 years after the start in learning the computer, but the development of China’s first professional anti-virus software in 2003, he.

    Reply to this comment
  31. cheap newport cigarettes | 12月 21st, 2011 at 14:41

    Your article is useful for me. It is a good article.

    Reply to this comment

我来说两句儿

可以在留言中使用以下标签 :<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree