By Developers, For Developers

Historical errata for Pragmatic Guide to JavaScript

PDF PgPaper PgTypeDescriptionFixed onComments
20TYPO

Fourth paragraph; “bracks” should probably be “brackets”

2010-10-05
30TYPO

last paragraph, “is not weel-suited’ should be ”well-suited"

2010-10-05
23ERROR

The inner function in the “private properties” needs to be executed to return the not so private variable.

I chose this approach:

(function innerFunc() {
notSoPrivate = 43;
return notSoPrivate;
})();

2010-10-05Actually my code works as it, as the wrapped function IS called. Also, the members marked as private (privateField and processInternals) are indeed private: because of the function wrapping and the "var" before privateField, they are absolutely inaccessible from outside scopes.
21TYPO

I think

var love = { firstName: ‘Élodie’, lastName: ‘Porteneuve’ };

is invalid json

var love = {’firstName’ : ‘Élodie’, ‘lastName’: ‘Porteneuve’ }

2010-09-16Actually this doesn't claim to be JSON, much less valid JSON. Only JSON per-se mandates quoting the key names, as this lets you use reserved words without any special case. \n \nThis also makes the explicit case that JS will systematically handle your object property names as Strings, so key 1 is the same as key '1'. \n \nBut object literals don't mandate quoting at all, when the keys you use are not reserved words (e.g. class).
89TYPO

Tasks overview, first item:
“We’ll first talk about cookies, on of the earliest ways of …”
should probably be
“We’ll first talk about cookies, one of the earliest ways of”

2010-10-05
68SUGGEST

You might want to point out this technique only works for forms that have only a single submit button. Forms with multiple submit buttons append the name and value of the button. Disabling submit buttons makes the browser ignore the submit button pressed and confuses forms which depend on the button name appearing in the HTTP POST/GET parameter list to tell which event is being processed.

2010-10-05This is a very good point; unfortunately, the exigencies of the book's format won't let me add another line to that text page :-/ \n \nI'll be sure to blog about it sometime on the book's site though, especially as there is another way (maintaining submit state in a private hash to cancel events after the first submit call) that doesn't require disabling the button.
35TYPO

“document.observe(‘dom:ready’, fx)” should read “document.observe(‘dom:loaded’, fx)”, correct?

112TYPO

Sixth line starting from the bottom:
“load scripts at the bottom of the ” and even more […]

The word ‘page’ is probably missing.

114TYPO

Last ¶:

Most of use web developers
=>
Most of us web developers

117SUGGEST

Middle of page:
PDoc (a code inline documentation system)
=>
PDoc (an inline code documentation system) ?

31TYPO

Y.one(‘#id’).append(’

This gets at top

’)

is incorrect, it should be:

Y.one(‘#id’).append(’

This gets at bottom

’)

119SUGGEST

“jQuery is, at the time of this writing, at version 1.4.2.”

This was already mentioned at the bottom of the previous page:
“(The current version at the time of this writing is 1.4.2.)”

It seems a bit redundant to state this fact less than 1 page later.

Also, the current release is 1.4.4.

102TYPO

Missing space in the first paragraph of section B.2: “grab Firebug at [URL]or from the Mozilla Add-Ons directory” (at the end of the first URL).

98TYPO

The top of the JavaScript Cheat Sheet identifies it as the “Pocket Guide to JavaScript’s” cheat sheet rather than the “Pragmatic Guide to JavaScript’s”.

98SUGGEST

I was hoping the Guide (or at least the Cheat Sheet) would include a reminder of JavaScript’s odd way of defining a new class. Perhaps in a future update?

7TYPO

JavaScript code in ‘Try this example: “privates properties.”, var publicField = ’foobar’; should be publicField = ‘foobar’;

7SUGGEST

One of the reported errata is itself possibly incorrect. There reported errata in question is:

“#46276: JavaScript code in ‘Try this example: “privates properties.”, var publicField = ’foobar’; should be publicField = ‘foobar’; —Klaus Rohe”

The code in the book is correct. Either version (that in the book or that suggested by Klaus) will work. I verified this in a JavaScript console myself.

However, the book’s version exports “publicField” by making it a property on the object returned from the anonymous function. The version suggested in the errata report, that of removing the “var” before the definition of the “publicField” variable is unnecessary. In fact, the only effect it has is to make said variable global (in the context in which you run said example). This actually breaks the spirit and intent of the code example and of what the section of the book it trying to demonstrate: keeping your own junk out of the global namespace.

Here’s my console session log (executed in the Chrome Browser’s JavaScript Console):

> var obj1 = (function() { var privateField = 42; var publicField = ‘foobar’; function processInternals() { alert(‘Internal stuff: ’ + privateField); } ; function run() { processInternals(); alert(‘Still private stuff: ’ + privateField); alert(‘Public stuff: ’ + publicField); } ; return { publicField: publicField, run: run }; })();
=> undefined
> var obj2 = (function() { var privateField = 43; publicField = ‘foobar2’; function processInternals() { alert(‘Internal stuff: ’ + privateField); } ; function run() { processInternals(); alert(‘Still private stuff: ’ + privateField); alert(‘Public stuff: ’ + publicField); } ; return { publicField: publicField, run: run }; })();
=> undefined
> obj1.run()
=> undefined
> obj1.publicField
=> “foobar”
> obj1.processInternals()
=> TypeError: Object # has no method ‘processInternals’
> obj1.privateField
=> undefined
> obj2.run()
=> undefined
> obj2.publicField
=> “foobar2”
> obj2.processInternals()
=> TypeError: Object # has no method ‘processInternals’
> obj2.privateField
=> undefined
> publicField
=> “foobar2”

Categories: