Errata

Knockout.js

Errata for Knockout.js

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
PDF Page 4,5
Example 1-4

on page 4 of the sampler pdf
=================================
Example 1-4. Object-Oriented ViewModel
var mySecondViewModel = function() {
var self = this;

self.name = 'Steve Kennedy';

self.getName = function() {
return self.name;
}
=================================
i think this is meant to be a I.I.F.E.
otherwise below codes on page 5 will cause errors

Example 1-5. Accessing the name property
alert(mySecondViewModel.name); // access the property name
alert(mySecondViewModel.getName()); // access the function getName

Allencx.Wang  Mar 19, 2015 
Other Digital Version 4-5
United States

I pulled the file cho1.html from the github repo and noted various errors when attempting open the file in both Chrome and FIrefox.
The first error in the browser console was: Uncaught Error: You cannot apply bindings multiple times to the same element. To correct this I did the following:
(1) Set the rendering of the name property in an element ID
<H1><span id="theName" data-bind="text: name">The Name Here</span></h1>
(2) Get the Element ID in the JavaScript code
var theElement = document.getElementById("theName");
(3) Clean the Element and then specify the element in the applyBindings constructor for the mySecondViewModel and myThirdViewModel ViewModels
ko.cleanNode(theElement);
ko.applyBindings(mySecondViewModel, theElement);

After this I then noted the following error:
Uncaught TypeError: mySecondViewModel.getName is not a function
This was corrected by João Nabais previous Errata entry. Here is my implementation of the mySecondViewModel View Model:
var mySecondViewModel = function() {
var self = this;

self.name = 'Steve Kennedy';

mySecondViewModel.prototype.getName = function() {
return self.name;
};
};
ko.cleanNode(theElement);
ko.applyBindings(mySecondViewModel, theElement);

Mark McFadden  May 07, 2015 
Printed Page 5
Portugal

The code:

alert(myFirstViewModel.name);

alert(mySecondViewModel.name); // access the property name
alert(mySecondViewModel.getName()); // access the function getName

Generates an Error. Probably the code should make use of the "Constructor Invocation Pattern":

alert(myFirstViewModel.name);

var secondVM = new mySecondViewModel();

alert(secondVM.name); // access the property name
alert(secondVM.getName()); // access the function getName

PS: I also changed the getName function (in order to make use of JS prototypal inheritance) from:

var mySecondViewModel = function(name) {
var self = this;

self.name = name;

self.getName = function() {
return self.name;
};
};

To:

var mySecondViewModel = function(name) {
var self = this;

self.name = name;
};

mySecondViewModel.prototype.getName = function() {
return this.name;
};

Best,

João.

João Nabais  Apr 18, 2015 
Printed Page 15
Example 3.3

I tried to follow the example from the book. However, when I refresh the page I received the following error message.

Uncaught SyntaxError: Unable to process binding "foreach: function (){return { data:books,afterRender:loadImage} }"
Message: Unable to parse bindings.
Bindings value: attr { id: 'image_' + isbn }
Message: Unexpected identifier

I thought I make a typo, but the example I ran after copy and paste straight from github doesn't work either.

Anonymous  Mar 12, 2015 
PDF Page 16
exercise 3.3

instead of :

<td><img src="images/loading.gif" data-bind="attr { id: 'image_' + isbn }" /></td>

place this:

<td><img src="images/loading.gif" data-bind="attr: { id: 'image_' + isbn }" /></td>

example works perfectly well!

Anonymous  Sep 27, 2016