Å·±¦ÓéÀÖ

Jump to ratings and reviews
Rate this book

The Principles of Object-Oriented JavaScript

Rate this book
If you've used a more traditional object-oriented language, such as C++ or Java, JavaScript probably doesn't seem object-oriented at all. It has no concept of classes, and you don't even need to define any objects in order to write code. But don't be fooled¡ªJavaScript is an incredibly powerful and expressive object-oriented language that puts many design decisions right into your hands.In The Principles of Object-Oriented JavaScript, Nicholas C. Zakas thoroughly explores JavaScript's object-oriented nature, revealing the language's unique implementation of inheritance and other key characteristics. You'll ¨CThe difference between primitive and reference values¨CWhat makes JavaScript functions so unique¨CThe various ways to create objects¨CHow to define your own constructors¨CHow to work with and understand prototypes¨CInheritance patterns for types and objectsThe Principles of Object-Oriented JavaScript will leave even experienced developers with a deeper understanding of JavaScript. Unlock the secrets behind how objects work in JavaScript so you can write clearer, more flexible, and more efficient code.

120 pages, Kindle Edition

First published December 18, 2012

135 people are currently reading
903 people want to read

About the author

Nicholas C. Zakas

17?books106?followers
Chinese: Äá¹ÅÀ­Ë¹

Nicholas C. Zakas is a front-end consultant, author, and speaker. He worked at Yahoo! for almost five years, where he was front-end tech lead for the Yahoo! homepage and a contributor to the YUI library. He is the author of Maintainable JavaScript (O¡¯Reilly, 2012), Professional JavaScript for Web Developers (Wrox, 2012), High Performance JavaScript
(O¡¯Reilly, 2010), and Professional Ajax (Wrox, 2007). Nicholas is a strong advocate for development best practices including progressive enhancement, accessibility, performance, scalability, and maintainability.

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
296 (49%)
4 stars
241 (39%)
3 stars
57 (9%)
2 stars
6 (<1%)
1 star
4 (<1%)
Displaying 1 - 30 of 62 reviews
Profile Image for Wojtek Ogrodowczyk.
44 reviews14 followers
September 7, 2017
tl;dr: I might've expected the wrong thing and I was disappointed.

The author walks through a bunch of *techniques* that you can use to write OOP code in JS, which is a nice for a reference book. However, what I hoped the book would tell me is *why* and *when* to use the OOP techniques. This question, however, remains unanswered¡­
Profile Image for Jacob.
6 reviews1 follower
January 7, 2015
First, my background and where I'm at as a developer:

I consider myself to be somewhere in between a novice and intermediate JavaScript developer. I have lots of jQuery experience as well as some MV* experience using Backbone.js. I've been exposed to more advanced concepts like closures and IIFEs, etc. - and I've even used them - but always felt a little foggy about exactly what was happening behind the curtain. I want to create games in JavaScript, and so I was looking to this book for some insight in regard to the underpinnings of Object-Oriented Design (OOD) with JavaScript. I was hoping to walk away from this book armed with the ability to begin work on my own JavaScript game engine using Object-Oriented Design (OOD) patterns.

Summary:

The book was very analytical and straightforward in its methodology of explanation. The content builds on itself very logically from chapter to chapter along with clear explanations and wonderfully annotated code examples. As other reviewers have mentioned, it's very dense material, but clearly written and not hard to understand if you take your time and reread/re-examine the code samples when concepts get hairy.

Much of the content is framed in a way of emulating Classical behavior from other languages in JavaScript (which uses prototypal inheritance rather than classes). This was somewhat less helpful to me, because JavaScript is the only language I know currently. Still - the concepts of class-based languages (Encapsulation, Inheritance, Polymorphism, etc.) are somewhat familiar to me, and the book helps bridge the gap between traditional methods of OOD and JavaScript. For anyone coming in with a traditional class based understanding - I suspect this book would be perfect for filling the gaps.

The final chapter is particularly good (though only 14 pages), as it FINALLY emerges from the "nuts and bolts" of OOD in JS and gives you some examples and use-cases for actually utilizing what you've been learning in all of the previous chapters. The Module Pattern of object creation and the explanation and rationale behind using closures finally makes sense to me, after being somewhat opaque in the past. I wish there was more to the final chapter. Which brings me to...

My only complaint:

Ultimately, the brevity and narrow focus of the book works to the content's favor, but I was hoping for some more practical examples and actual use cases. To me, it felt like the last chapter was the only one in which I walked away with a very clear understanding of how I could use some of these nuts and bolts in an advantageous way. The whole book felt like a thorough examination/explanation of a carpenter's toolbox and all the different tools, but mentioned little in the way of how to construct a house. I suppose teaching design patterns isn't really the objective of the book, though. I'll have to look elsewhere for that.

So there you have it. This book truly is the PRINCIPLES of OOD in JavaScript, not the patterns. It was still a great read, and I know I will definitely reference it in the future.
Profile Image for Lim Hooi.
6 reviews1 follower
Read
January 18, 2015
This was a good book for anyone who wanted to know some of the Javascript fundamentals especially when for the last couple of years, projects were heavily depend on frameworks and 3rd party libraries. For instance, frameworks have functions to create instances of Javascript class. Where does the keyword new sit in? There is more than one way to "new" a class, So do I go ahead with var o = new Object or var o = {}. This is, surprisingly, confusing for someone who did not follow Javascript thoroughly but going in and out of Javascript to fix a bug or to get the Javascript ready to show end results in web browsers. There is no difference between the previous statements. Behind the scene, an instance is created and it is a relief to have a confirmation from someone with a solid experience in Javascript. However, this book does not going into frameworks or libraries but the basic Javascript syntax and rules.

The book went on to explain Object's contructor and prototype. If you do not know, Javascript uses prototype-based style for OOP which is quite different from Java or C++. This is where constructor and prototype fields get confusing, again, for someone like me who had been using Java for many years. This is clearly explained in the book along with other attributes to make classless-based programming work in Javascript ecosystem.

In summary, this is a good book to read if you want to know why the 3rd party libraries or frameworks did it the way they did. This helps the reader to differentiate the fundamental methods from framework preferred ways of doing the "same thing". It also mentioned about super which is pretty common in OO languages. In case you were wandering why I highlighted this, super is not a Javascript keyword.
34 reviews2 followers
June 2, 2014
After Reading this book, I really learnt a lot about OOPS in JS. Now I know

1. How to create a readonly property in an object.

2. How to create an object which cannot be overridden.

I haven't completed it yet. But its awesome.


Must read for every JavaScript Developer
Profile Image for Yousef Meska.
18 reviews4 followers
May 3, 2021
well actually I am a little bit confused about giving 5 stars to it, but I gave it 4 stars because however this book is giving you the underlying mechanisms of JS oop and it's internals, it didn't provide exercises or even questions to make your hands dirty
love it
625 reviews23 followers
March 9, 2015
JavaScript is a rather strange language. Its roots come from the Netscape browser heyday, and it gives the impression that it was rather hastily created. Complicating this was the fact that, at the time, Java was a recent phenomenon, and the Netscape management thought it would be a good idea to make JavaScript popular by riding on Java's coattails. This turned out to be a terrible idea -- it meant that JavaScript was renamed, and rewritten to mimic a lot of Java syntax, and, as a result, it caused a huge amount of confusion because it looked like Java while in fact being a very different language. The languages use totally different models. People are still confused by that today, 20 years later.

Add to JavaScript's oddities the fact that, while there are a lot of JavaScript books, most of them seem to concentrate on Java as a procedural language, and there was (and still is) a lot of emphasis on "learning" JavaScript by cutting and pasting other people's code, without understanding the fundamentals of the language. This produced some really bad practices. In fact, books have been written criticizing JavaScript, and advocating limiting the use of many JavaScript features -- for example: .

Then, there is the fact that JavaScript is used almost (but not completely) exclusively in Web browsers, and so you have to not only know the language but also understand how it fits in the web browser context, and learn about additional JavaScript objects such as Document and Window, and the like -- the so-called DOM (Document Object Model), which is so important when dealing with web pages and JavaScript. This adds enormous complexity to a misleadingly "simple" language.

Some time ago, I was teaching a course in Web Development, and tried to teach JavaScript by teaching good practices, and I tried to explain (and use!) JavaScript's oft-touted object-orientation. Java is a class-based object-oriented programming language. On the other hand JavaScript does not have classes; it uses what is referred to as prototype-based object orientation. At the time I was researching and teaching the course, I found precious few resources to help me with those aspects of JavaScript. This was exacerbated by the fact that Netscape was using their own, original, version, while Microsoft had reverse engineered JavaScript and came up with their own version, JScript. Inevitably, there were incompatibilities that made the problems far worse. So I never finished my goal of teaching JavaScript to the level of how to use it object-orientation -- at least, to my satisfaction.

This book would undoubtedly have helped me in that long-ago quest. It is the first book I've seen that deals explicitly with the JavaScript object model, and it does so in a reasonable way. But I only say reasonable, because of the following:

1) The book is way too short. While brevity is often desirable (and too many JavaScript books go to the other extreme), here it is too abbreviated.
2) More, more varied, deeper, more realistic, and longer examples are needed for those of us who need to see more specifics before effectively applying the general principles. Succinct examples are good, but not in and of themselves sufficient; the book needs to use the existing shorter examples as a springboard towards more realistic examples, where we have a greater chance of seeing how they might be applied in the real world.
3) I noticed that I was halfway through the book, and we were still not truly dealing with objects; the first half was providing background, even though we had read early on that the book is not for beginners.
4) The last chapter ("Object Patterns") was a major disappointment. I was hoping to see the principles from the earlier chapters being applied to implement some common object-oriented patterns, such as are found in the now-classic: -- clearly, not in the same amount of detail, but something that allows us to apply the ideas and skills learned in the earlier chapters on something semi-realistic.
5) Throughout the book, the description and examples were relatively straightforward -- perhaps, as mentioned above, too much so. However, in the last chapter, the descriptions and examples rapidly escalated in complexity. Perhaps this is inevitable because of the material being covered, but I believe that the descriptions in particular would be much better if explained less succinctly. The impression is that there are a small number of topics to be described, and perhaps the writer was feeling the need to finish, and get the book published and for him to move on to other things. This was unfortunate, because this is where the book could have shone -- it should have been so much better here than it actually was (see point 4), above).

For this reason, I only gave the book four stars. (I would, if I could, have given it 3 1/2 stars)

I would love it if the author could develop a later edition of this book along the lines suggested above. The result would be a much better book than the current edition.
Profile Image for Mahmoud Shrif.
43 reviews74 followers
March 17, 2024
?? ???? ??? ?? ??? ?? ?? ???? ?? ???? ????? ??? ????? ??? ?????? ??? ?? ????? ???? ????? ???
?? ??? ??? ????? ?? ???? ???????????? ????? ???? ?????
?? ?? ?? ???? ??? ?????? ???? ???????????????????????????????? ???????
????? ? ???????? ???? ?????? ????
???? ???? ???? ???? project or exercise or exploring some concepts like this keyword
Profile Image for Az Vera.
Author?1 book8 followers
April 20, 2017
This is a solid and comprehensive overview of object-oriented (OO) programming with JavaScript; focusing on using OO principles in JS after coming from more "traditional" class-based OO languages like Java. It covers a lot of the features brought into ECMAScript 5 which is probably the most prevalent version available today (it'll be a while before ES6 is available everywhere) and thus most relevant for developers aiming to have their software work on any browser and on any platform.

The material is dense without making the reader feel they've missed a step and avoids dragging it's heels too much; it relies on very simple and occasionally repetitive examples but by re-using the same concepts/models each time it shows how each newly-introduced concept differs from the one before.

The language is plain and straight-forward, in this manner it avoids becoming repetitive or dry while also avoiding the whimsical humour in some programming textbooks (, ) which can distract from the concepts at hand. This does make the text strictly a guide for those trying to brush up on a topic, it doesn't contain much in entertainment value so I'd keep a fiction book on hand for when you need a break.

Overall I'd strongly recommend this to anyone looking to up their JS game; if you're looking to put more work into Node.js or start doing some slick client-side apps with more complex data models this is a must-read. I'd strongly recommend having some experience in JavaScript prior to getting into this and a passing knowledge of an OO language like Java, Python, or C#.
Profile Image for Rob.
Author?2 books428 followers
March 17, 2023
has a new (and short!) book out on Leanpub called Principles of Object-Oriented Programming in JavaScript. Remember the OOP coverage from his ? It¡¯s like a deep-dive version of that. Recommended.

I had the privilege of getting some early looks at this book and am glad he pulled the wraps off of it to share with everyone.

Zakas goes into the gritty details of the various OOP patterns that are available and idiomatic in JavaScript. After some technical introduction into some of JavaScript's low-level details (mostly around the primitives and reference types), he gets in to the different patterns, touching on the tried-and-true (if flawed) methods that we relied on from back in the ECMAScript 3 days, through to the new and native ECMAScript 5 methods. He also gets into mixins and scope-safe constructors.

Good stuff.
Profile Image for tiff.
67 reviews25 followers
April 30, 2016
Great, quick read that will help any new or intermediate JavaScript or web developer get more familiar with OOP JavaScript.

The best parts of the book for me coincide with the things I am learning at Treehouse during their OOP JavaScript course in the full-stack JavaScript Track.

As far as the OOP nature of JavaScript. A lot of the syntax and ideas borrow heavily from Java and it is evident when I am writing in JS. Fortunately, the book stresses the Prototypal Inheritance of JavaScript instead of thinking about it in a Classical Inheritance type of way. Eric Elliott has already crooned the virtues of Prototypal Inheritance, which is a feature of JavaScript people either love or hate.

I learned a lot in this book, that really just gave me a slightly more in depth look into the stuff I was already learning. Having gone to Pitt for two semesters and taking CS classes, a lot the OOP stuff was familiar as Java is a Classical OOP language. But thinking about it in the JavaScript way was helpful. Four stars.
Profile Image for Ashraf Bashir.
227 reviews134 followers
July 19, 2014
The book is very useful, it puts your legs on the right first step toward OO in JS, and it quickly dig you deeper with dirty hands, especially that it's very easy to follow the author's progress in it. Also it's a small size book, which makes you quickly "ready to go". But as it's a small size book, it's very concentrated, so don't bypass any point or section which you didn't get well, you will need it very soon in the book. Chapters are built over each other, so be sure to read some chapters/sections twice if you didn't get any well. The only part which I didn't like is the patterns chapter (last chapter); it's very abbreviated, there's a lot more to say, but this is expected and acceptable because the author is just teaching you the "principles", and he didn't promise you to master all aspects of JS OO in just a "One Hundred Pages" book. Anyway, it's worth reading for developers and designers.
Profile Image for Derek.
53 reviews3 followers
May 13, 2016
If you're interested in how the flexible JavaScript supports Object-Oriented programming, and want an in depth, practical guide, this book is a fantastic read.

While it isn't long, it's helpful code walkthroughs and background information on the inner workings of JavaScript make it a high-impact read.

I'm looking forward to an updated edition for ES6!

Profile Image for Devin.
405 reviews
November 6, 2017
A clear - if not overly descriptive - account of object-oriented principles as they would be realized in javascript. It doesn't dwell on the advantages of encapsulating data, but rather the nuts and bolts of how one goes about doing it. The advantages become clearer with each chapter. It also clarified a number of design patterns that one encounters in web development.

The next step will be to apply these principles to my next project...
Profile Image for IOANNIS TSIOKOS.
13 reviews
July 25, 2018
Short and sweet, without repetition and very well structured. If you have approached javascript from another programming language, you are probably guilty of writing code that tries to be something that it is not. Javascript is a powerful language with its own set of "special skills". This book does a great job showing you how javascript is different and how you should use it. You might just have to read it a couple times and apply the concepts before you get a good grip on the language.
22 reviews
October 31, 2017
Nicholas C. Zakas really knows his Javascript craft. Very well written, short and clear. Every sentence, every word, has a meaning. These days, one might consider it a bit obsolete (since Javascript language has been at extreme pace of changes for the past few years), but still mandatory for a starting JS programmer that seeks proper understanding of the language core.
Profile Image for Pam.
1,080 reviews
Read
August 19, 2019
An extremely valuable book that explains how in the world JS can possibly be thought of as object-oriented language (with no classes?!?!?). The book does an excellent job covering a variety of important aspects of JavaScript (e.g., inheritance, functions, constructors, etc.). An excellent reference book.
1 review
December 15, 2019
This is one of the best intermediate-level JavaScript books that I have read. It clearly describes subjects at hand and does not confuse the reader with unnecessary and unrelated details even though it is full of detailed instructions related to the language. I suggest this book to you if you have some basic knowledge of JavaScript or any other object-oriented programming language experience.
Profile Image for Johnny Reina.
3 reviews
September 14, 2017
A solid book for those who are serious about applying what they know about class-based OOP to JavaScript. As it turns out there is a lot more to JavaScript objects than a bunch of key-value pairs between a set of curly braces.
Profile Image for Emre Ergin.
Author?10 books83 followers
June 16, 2022
I am not expert enough to evaluate how much of this book solves unnecessary concerns now that the class interface is added to JavaScript. However, most of it was still useful to understand the default approach, both as a summary and as a source of good example codes.
Profile Image for Osama Rabea.
1 review
February 4, 2025
This book is topnotch!.The content is well-structured, and the language is easy to follow¡ªclear, smooth, and to the point. It explains the fundamentals of object-oriented programming in JavaScript without unnecessary complexity. Overall, it's a useful and straightforward read.








22 reviews
December 14, 2017
Great book for programmers with a real background in real OO languages trying to make sense of JavaScript.
Profile Image for Keith.
114 reviews2 followers
January 19, 2018
A great read but it is ready for an ES2015+ refresh. I still came away from it with lots of useful insight and a much better grasp of OO concepts.
Profile Image for Mohamed Krid.
8 reviews
October 19, 2018
very interesting book , the explanation is very understandable . this book takes you step forward in understanding the javascript engine mechanism
Profile Image for Derek S..
31 reviews
March 22, 2020
Slightly out of date, but clear, concise introduction to inheritance in JavaScript.
Profile Image for Pavel Karateev.
18 reviews5 followers
January 21, 2021
An excellent primer on OOP in JS. It doesn't cover ES6 but the detailed knowledge of prototypes and properties machinery will likely be useful nonetheless.
Profile Image for Jac.
457 reviews
March 19, 2017
it's a pretty short book and all the fundamentals were familiar, but I still found some neat tidbits of knowledge that I may never specifically use, but which round out my understanding of the language.
25 reviews
December 24, 2019
A concise but very informative overview of prototype-based inheritance in JavaScript. This book covers many of the more unusual (and at times very useful) features of the language, while also discussing a variety of approaches to approximating more traditional object-oriented software design in JS.

While ES6 introduced classes to JavaScript, which allows you to define classes and inheritance using syntax more comparable to traditional objective-oriented languages like C++ and Java, it is "syntactical sugar." Prototype-based inheritance is still how the language works under under the hood.
Displaying 1 - 30 of 62 reviews

Can't find what you're looking for?

Get help and learn more about the design.