Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Error in the book. Guia Definitivo JavaScript 6°Edição David Flanagan (Tradução de João Eduardo Nóbrega Tortello).

Duvida Brazil-Português (BR, PT) {
Livro Guia Definitivo JavaScript 6°Edição David Flanagan (Tradução de João Eduardo Nóbrega Tortello)

Erro no capitulo 8 Funções, Exemplo 8-3 :
2 erros que compromete meu breve conhecimento dessa linguagem:
1°) for(var j = 0; j < protoprops.length; j++) ... sendo que protoprops só é declarado depois.
2°) if(source.haOwnProperty(prop))... Da erro porque source só é declarado depois, var source = arguments.length;
Dois erros parecidos que faz o exemplo 8-3 (Pagina 175), ficar estranho de entender, e gera erro no Firebug, ou Modo Desenvolvedor - Console de qualquer navegador !!

Espero que me corrigem isso, e obrigado pela atenção.
}

Google Translate:

Doubt Brazil-Portuguese (BR, PT) {
Book Definitive Guide JavaScript 6th Edition David Flanagan (Translation of John Edward Nobrega Tortello)

Error Functions in Chapter 8, Example 8-3:
2 errors that compromises my brief knowledge of this language:
1°) for(var j = 0; j < protoprops.length; j++) ... being that is only declared after protoprops.
2°) if(source.haOwnProperty(prop)) ... the error because source is declared only after, var source = arguments.length;
Two similar errors that makes the example 8-3 (Page 175), get weird to understand, and generates error in Firebug, or Developer Mode - Console !! any browser

I hope you correct me, and thank you for your attention.
}
1 person has
this problem
+1
Reply
  • Hello,

    I have forwarded your question on to our Book Tech staff, so they can help you find a solution. If you ever have any questions or issues with the content of a title, you can also contact them directly at booktech@oreilly.com or call them at:

    1-800-889-8969
    or
    1-707-827-7019 (outside the USA)
    7:30 am to 5:00 PST

    Best regards,
    Paul Fichera
    O'Reilly Media
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated kidding, amused, unsure, silly

  • Hi,

    I don't think there is an error in that section. There was a correction for example in the errata page, and it was corrected in Aug 12, 2011 reprint, so I don't know if the translated version got corrected.
    http://www.oreilly.com/catalog/errata...

    Here is the corrected example code -

    Example 8-3. The extend() function, patched if necessary
    // Define an extend function that copies the properties of its second and
    // subsequent arguments onto its first argument.
    // We work around an IE bug here: in many versions of IE, the for/in loop
    // won't enumerate an enumerable property of o if the prototype of o has
    // a nonenumerable property by the same name. This means that properties
    // like toString are not handled correctly unless we explicitly check for them.
    var extend = (function() { // Assign the return value of this function
    // First check for the presence of the bug before patching it.
    for(var p in {toString:null}) {
    // If we get here, then the for/in loop works correctly and we return
    // a simple version of the extend() function
    return function extend(o) {

    for(var i = 1; i < arguments.length; i++) {
    var source = arguments[i];
    for(var prop in source) o[prop] = source[prop];
    }
    return o;
    };
    }
    // If we get here, it means that the for/in loop did not enumerate
    // the toString property of the test object. So return a version
    // of the extend() function that explicitly tests for the nonenumerable
    // properties of Object.prototype.

    // This is the list of special-case properties we check for

    var protoprops = ["toString", "valueOf", "constructor", "hasOwnProperty",
    "isPrototypeOf", "propertyIsEnumerable","toLocaleString"];
    return function patched_extend(o) {
    for(var i = 1; i < arguments.length; i++) {
    var source = arguments[i];
    // Copy all the enumerable properties
    for(var prop in source) o[prop] = source[prop];

    // And now check the special-case properties
    for(var j = 0; j < protoprops.length; j++) {
    prop = protoprops[j];
    if (source.hasOwnProperty(prop)) o[prop] = source[prop];
    }
    }
    return o;
    };

    }());


    If you are still getting errors with that, please send me the complete code you are using and the error messages that you are getting so I can pass them to the author.

    Best regards,
    Chris Olson
    O'Reilly Book Support
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated kidding, amused, unsure, silly