Errata

Programming JavaScript Applications

Errata for Programming JavaScript Applications

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
ePub Page 1
Chapter 2, Always Use Var, Right: Function Scope

In the test('With var.' ...

ok( !x, 'x should not pollute the global scope.');

This test dies in qunit v 1.11.0 because x is not defined. The test that worked for me is:

equals(typeof x === "undefined", 'x should not pollute the global scope');

templemang  Jan 30, 2013 
ePub Page 1
Chapter 2, Always Use Var, Right: Function Scope

Correction to previous erratum submission:


the test that works is:

test('With var' ...

equal(typeof x, "undefined", 'x should not pollute the global scope');

templemang  Jan 30, 2013 
Other Digital Version 1
1

I'm reading the digital preview available in HTML format at
http://chimera.labs.oreilly.com/books/1234000000262/ch03.html

In the Chapter 3 (Functions), minimize side effects sections, I see the following:

> At this point, cart.items is a reference to the prototype items attribute. This is improved with one small change to the code:

I think that sentences is wrong, and is also misleading. At that point, cartProto.items is:

cartProto.items === []

the problem is that

savedCart.tems === cart.items

If you want to show the problems that might arise when inadvertently accessing the protoype properties you could use the addItem directly.

You could modify the example like this

createCart = function (items) {
return Object.create(cartProto);
}

session = {
get: function get() {
return this.cart;
},
// Grab the saved cart.
cart: createCart()
};

// create another cart instance,
// to show that they both point to the prototype's items array
anotherCart = createCart(),

// addItem gets triggered by an event handler somewhere:
session.cart.addItem('grapefruit');

ok(session.cart.items.indexOf('grapefruit')
!== -1, 'Passes: Session cart has grapefruit.');

ok(anotherCart.items.indexOf('grapefruit') === -1,
'Fails: A different cart is unchanged.');

ok(session.cart.items !== anotherCart.items),
'Fails: Each instance should have their own items.');

ok(session.cart.items !== cartProto.items),
'Fails: Each instance should shadow the prototype\'s items array.');

ok(anotherCart.items !== cartProto.items),
'Fails: Each instance should shadow the prototype\'s items array.');

--

I wrote an article with a bit more complicated example

http://opensas.wordpress.com/2013/06/09/troubleshooting-javascript-humble-homage-to-wat/


Sebastián Scarano  Jun 22, 2013 
Other Digital Version 1
1

Just a question, I see in chapter 3, functions, Minimize side effects session, that you are using Object.create just like it is usually used _.clone, that is to make a copy of an object and avoid modifying an argument you receive.

I just wanted to ask if I understood correctly, and if there are any drawbacks to this approach (for example, what happens with shallow / deep copies, etc.)

Sebastián Scarano  Jun 22, 2013 
PDF Page 42
New York

The sample code, which is supposed to be erroneous, looks correct; it already contains the call to bind() which the text says needs to be added. Also, the indentation of the code doesn't match the brackets.

Shawn William Lauzon  Aug 18, 2012 
PDF Page 43
2nd

The dot notation sample invokes the function and the square bracket notation returns the function itself.

...

Method invocation applies the function to the object to which it is attached. It takes the
form, object.methodName() (dot notation) or object['methodName'] (square bracket
notation).

...

Jan Prinsloo  Jun 28, 2013