Review of "Principles of Object-Oriented JavaScript" by Nicholas Zakas

Excellent book from a master who explains one area of JavaScript in detail.

"Principles of Object-Oriented JavaScript" by Nicholas Zakas, ISBN 978-1593275402

While I did not find too many things new to me in this slim book, it was a great refresher on object-oriented mechanics of JavaScript. Here and there I found interesting tidbits.

A useful explanation in chapter 4 why when setting an object's prototype using this syntax

1
2
3
4
function Person() { ... }
Person.prototype = {
// shared functions
};

you should also restore the constructor property

1
2
3
4
5
function Person() { ... }
Person.prototype = {
constructor: Person,
// shared functions
};

Hint: you don't need to do this if you add functions to prototype one by one

1
2
function Person() { ... }
Person.prototype.getName = function () ...

Second useful reminder in chapter 4: sealed or frozen object's prototype is NOT sealed or frozen. You can still modify the prototype and potentially affect the object's behavior.

I liked this book for its clarity and preciseness. Each example demonstrates exactly the topic at hand: constructor stealing, prototypical inheritance, etc. The writing is very very clear, and while this book is not for JavaScript beginners, I highly recommend it to anyone trying to reach a higher level.