Jump to ratings and reviews
Rate this book

You Don't Know JS #3

You Don't Know JS: this & Object Prototypes

Rate this book
No matter how much experience you have with JavaScript, odds are you don't fully understand the language. This concise, in-depth guide takes you inside JavaScript's this structure and object prototypes. You'll learn how they work and why they're integral to behavior delegation--a design pattern in which objects are linked, rather than cloned.

Like other books in the "You Don't Know JS" series, this and Object Prototypes dives into trickier parts of the language that many JavaScript programmers simply avoid. Armed with this knowledge, you can become a true JavaScript master.

With this book you will:


Explore how the this binding points to objects based on how the function is called
Look into the nature of JS objects and why you'd need to point to them
Learn how developers use the mixin pattern to fake classes in JS
Examine how JS's prototype mechanism forms links between objects
Learn how to move from class/inheritance design to behavior delegation
Understand how the OLOO (objects-linked-to-other-objects) coding style naturally implements behavior delegation

171 pages, Paperback

First published June 25, 2014

243 people are currently reading
1439 people want to read

About the author

Kyle Simpson

37 books360 followers
Kyle Simpson is an Open Web Evangelist from Austin, TX, who's passionate about all things JavaScript. He's an author, workshop trainer, tech speaker, and OSS contributor/leader.

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
731 (58%)
4 stars
410 (32%)
3 stars
95 (7%)
2 stars
15 (1%)
1 star
1 (<1%)
Displaying 1 - 30 of 81 reviews
Profile Image for Mark.
143 reviews6 followers
April 4, 2018
I think this is the most verbose book in the series so far, but I get the point that classes are not copies. The author really drives that point home. However, having no experience with classes has a lot of the examples being wasted on me. I wish he went with a newbie approach, but it was good to see what others may be doing!
Profile Image for Alexander.
64 reviews22 followers
March 24, 2018
I have no complaints on the section explaining how "This" works, but the sections covering "Prototypes" and "Object Creation" where more complex than necessary, even the ECMAscript Documentation has easier ways of explaining these concepts without generating much confusion
Profile Image for dantelk.
208 reviews20 followers
February 1, 2025
The first half of the book, on "this" keyword was well explained (still I had to read that part twice, supplementing the context with youtube videos). I think the second part on prototypes was too deep dive, and I think the complexity of the matter may not be only JS's fault anymore, but the author's too.

Some content creators on Youtube play Fatboy Slim's "Weapon of Choice" for the "you can do this you can do that" lyrics. I think Danny Elfman's "What's this" from the Nightmare Before Christmas is more appropriate for a song on "this" on JS.

I recommend this book to all JS developers, and I am terribly sorry for that. It's great that this book exists and it'a terrible that we have to read it to understand the complex internal mechanisms of JS. I gave the book three stars, because I think the context should have been written in a more understandable way - a book shouldn't require more resources for help while been read. That said, I believe it should be on the reading list of those in the industry.
Profile Image for Alisher Abdurakhmanov.
34 reviews1 follower
March 18, 2018
Я в восторге от этой книги! Последние три главы читал как остросюжетный детектив, на одном дыхании. Вдохновился паттерном OLOO — надо будет обязательно попробовать; а ещё подумать, как применять в TypeScript, где всё так и просится в OO. Хорошо бы ещё выкроить время, чтобы пройти видеокурс от самого Кайла Симпсона. Вперёд, к новым знаниям!

OLOO is an extremely powerful design pattern, very distinct from the idea of parent and child classes, inheritance, polymorphism, etc. Rather than organizing the objects in your mind vertically, with Parents flowing down to Children, think of objects side-by-side, as peers, with any direction of delegation links between the objects as necessary.
Profile Image for Ryan Boone.
15 reviews5 followers
December 21, 2015
For experienced and inexperienced alike

This book is a must, whether you are a JS newbie or have been in the programming trenches for years. In it, Kyle Simpson explains the inner workings of two of the most misunderstood and misused features of JS, `this` and Object prototypes.

This `this` portion clearly outlines the criteria and priority JS engines use to determine a particular function's call site or context, which in and of itself is enlightening.

The real value, in my opinion, comes from the Object prototype section. Simpson does an excellent job of explaining prototypal inheritance, and why inheritance is in and of itself a bad term to use with regards to JS. If you are a programmer coming from a traditional classical-inheritance language, this should clear up a lot of confusion you may have.

Simpson's call for an OLOO workflow is clearly reasoned through showcasing the difficulty of bending JS to emulate a Class workflow vs. simply interacting directly with the objects themselves. He even includes an appendix outlying his argument against the `class` syntactic sugar added in ES6/ES2015 (still not true class support).

Ultimately, this book is Simpson's plea that we see the dynamic power JS has and use it the way it was meant to be used.

Note: this book is available for free on github, but I highly recommend you buy it as you will want to make many notes.
Profile Image for Jarek.
139 reviews11 followers
December 12, 2016
As in all books in the series, the author gets to the bottom of things, explaining all the nuances and idiosyncrasies of the language. The second part of this book is a bit opinionated, but it does not stand in the way of providing exhaustive information on the subject.
Profile Image for Temo Tchanukvadze.
54 reviews8 followers
November 3, 2018
I knew JS was mind blowing but after readimg 'this' and prototypes It blew the hell outta me
Profile Image for Iain Davis.
14 reviews1 follower
March 16, 2025
You Don't Know JS: this and Object Prototypes is the third book in the the well-regarded You Don't Know JS series.

Note that, at the time of this reading, there is not yet a released second edition of this & Object Prototypes. As a result, this and my reviews of the remaining books in this series will likely deal with the first editions.

I'm not really finding myself persuaded by these books. Partly because I feel that the author is trying so hard to persuade me of certain things that I find wholly unconvincing. I suppose, if I'm honest with myself, I'm a React developer, more than I am a JavaScript developer (although I am trying to expand my skillset). And I also have a fondness for TypeScript. As a result, I think I come into the space with a different set of assumptions than Kyle Simpson assumed his readers would have, back in the pre-React days when ES6 was brand new and a bit mysterious.

The author assumes his reader has foolishly been beguiled by the siren song of near-ubiquitous OOP. treating JavaScript's prototype mechanism (which he insists we should not think of as "inheritance" at all, but delegation) like class inheritance. He spends the bulk of the book trying to make the case that JavaScript delegation (his preferred term) pattern is better described as "delegation" and we should all be using idioms that make that mental model explicit and clear.

I'm not sure at all that I agree with him... I think if you're comfortable with that model, it's probably fine, but I also think if you're comfortable thinking in class-like terms, it's not that far a stretch. If it's easier for you (and your team) to think in classes and make allowances for JavaScript's quirks, then by all means, do that please. To be sure, there was a time when OOP was not just dominant, but nearly ubiquitous, and being able to make use of existing mental shorthands probably got a lot of projects off the ground faster than they otherwise would have.

That said, in the world post-React (and it's descendants), I think the hegemony of the Object-Oriented paradigm is not what it once was anyway. Functional idioms, even in the absence of "pure" functional programming, have become much more the norm. Which, it seems to me, renders a lot of Mr. Simpson's frustration moot, unless you happen to be working in legacy code.

As a result of this disconnect, I find this book is often trying to persuade me of better ways to solve problems I do not have. As with the previous book, I find the author sometimes makes excuses for his preferred way of doing things, while damning the "class" mental model for having exactly the same kind of faults. For instance, the author warns against dangers (and just syntactic ugliness) that can arise from trying to treat objects like classes (mutability of the shared behavior of "derived classes", for example), but largely excuses the obnoxiously variable behavior of this.

For my part, the main thing I hoped to get from this book was a better understanding of the this keyword, which I seldom use. And I did get that. I have a better understanding of how this works. More than anything, this understanding has led me to the conclusion that this should be used sparingly, if at all. Debugging this often requires checking the call stack just to determine which semantics apply. Worse, functions using this can **lose their binding** when passed as callbacks or reassigned.. Sure there are ways to resolve that issue, but those problems are going to be hard to spot, and I'm not sure why I really need the mental load of storing all the possible exceptional cases around this anyway. For anybody who recognizes the value of functional programming (even if they are not a purist), this is horrifying behavior.

Now, it's not Mr. Simpson's fault that this is painful to use, but it is a bit weird that he advocates it while suggesting in very strong terms that no-one should ever treat a function like a constructor. If you take my advice, you'll reserve the use of this for the constructors of ES6 classes (that Mr. Simpson argues we should never use anyway).

I also find, as in previous books, that there is a great deal of special pleading in this book, as in the following passage where he condemns the assumed semantics of the .constructor property:

Consider:

function Foo() { /* ... */ }

Foo.prototype = { /* ... */ }; // create a new prototype object

var a1 = new Foo();
a1.constructor === Foo; // false!
a1.constructor === Object: // true!


Object(..) didn't "construct" a1, did it? It sure seems like Foo() "constructed" it. Most developers think of Foo() as doing the construction, but where everything fall apart is when you think "constructor" means "was constructed by," because by that reasoning, a1.constructor should be Foo, but it isn't!

Well... yeah. If you deliberately break that mechanism, then the mechanism ceases to work. Is that a revelation? More to the point, if you find the .constructor property useful in your code it's pretty easy not to do this. Again the author has to introduce a contrived, not especially realistic case to support his argument. I think the point he's trying to make is that this isn't a robust and authoritative solution for the problem of identifying what created the object, but that seems a pretty weird thing to get hung up on when writing about JavaScript which, as a dynamically-and-weakly-typed language, is famously flexible and loose-y goose-y with its requirements. I also take issue with the tone of the above passage. That sense of contempt and superiority is throughout this book, and it can become a bit exhausting.

Again, I did learn things from this book. I got a better understanding of the this keyword, as well as property descriptors, and a handful of methods I didn't know about, like isPrototypeOf. But it's buried in a lot of arguments about how I ought to be writing my code that I don't agree with, and weren't really necessary to the stated aim of the book (exploring lesser understood areas of the JavaScript language).

I'm not sure this book knows what it means to be. On the one hand, it purports to be a general survey of the JavaScript language, so we get things like a discussion of the basic Object-Orientation principles (encapsulation, inheritance, polymorphism... abstraction is left out of explicit discussion but touched on tangentially). These concepts are the Bruce-Wayne's-parents-dying-in-an-alley of the software development world. We all see it again with every new reboot. It's Peter-Parker's-Uncle-Ben-dying. On the other hand, it aims to be these looks into esoteric nooks and crannies of the language. This is where I think most of the book's value lies, but it reduces the value of this book to someone just starting out in JavaScript, and the introductory concepts reduce the value for someone who is already experienced. I return to my previous assertion that a lot of the value in this book could have been delivered more effectively as a series of blog posts. On yet another hand (look, no analogy is perfect, okay?) it's a polemic against changing patterns of JavaScript code writing. It's this guise that takes up most of the book's bulk, and which I find the most exhausting and tedious.
Profile Image for Toros Yesja.
154 reviews19 followers
October 25, 2017
The book does teach you this & prototypes in a really good way.

Everything goes well until the 4th quarter of the book, where most of it becomes subjective, especially the Behavioral Delegation chapter. See this Reddit thread to see what i mean.
50 reviews10 followers
October 8, 2017
Please read carefully. It's a lot to digest, for JS beginners. Prototypal Pattern is discussed here. It's completely another type of pattern, that most of the people are not familiar with.

Kyle Simpson, did a great job!
I think I need to read it one more time, to fully grab the details.
Profile Image for Finlay.
318 reviews24 followers
December 3, 2014
Another solid review of the internals of JS. All devs should probably read this, if only to drive the idea out of their heads that OO and inheritance are somehow intrinsic to software.
Profile Image for Katherine.
149 reviews
July 5, 2015
There should be code of conduct for writing technical books. Avoid using "she" when the statement is negative.
9 reviews1 follower
November 7, 2015
Perfect in-depth analysis of how 'this' keyword and Object works in JavaScript, must read for high level understanding of Object and context in JavaScript
Profile Image for Eder Sanchez.
57 reviews6 followers
April 26, 2016
La explicación de OLOO está bastante buena y lo apruebo mil veces más que trabajar con prototype.
Profile Image for Tareef Mando.
134 reviews367 followers
March 9, 2019
الكتاب الثالث من سلسلة أنت لا تعرف جافاسكربت، والتي تُركز على نقاط يُساء فهمها بشكل شائع بين المطورين، وسلوكات دارجة لا ينبغي الاقتداء بها. لهذا السبب تجده عندما يبدأ بشرح نقطة ما يستعرض كافة الممارسات الخاطئة التي تدور عليها ويناقش بالتفصيل لماذا "يعتبرها" كذلك، ثم بعد ذلك يعرض مايراه ممارسة صحيحة ونهجًا أسلم، مع الشرح.

من هنا قد لا تكون هذه السلسلة هي المدخل الأنسب للمبتدئ الجديد الذي يرغب بالقراءة عن وتعلم جافاسكربت، ممن لا يملك أدنى فكرة عن الممارسات التي يتحدّث عنها، وإنما يهتم بتعلّم الممارسات الموصى بها وفقط.

أيضًا تُناسب هذه السلسلة المبرمجين القادمين من لغة أخرى ربما أكثر من القادمين الجدد إلى عالم البرمجة نفسه، حيث يفترض المؤلف في كثير من المواضع أن مطوّر جافاسكربت "يُفكّر بالأسلوب التالي أو يتوقع السلوك التالي" بينما المبرمج الجديد الذي بدأ لتوّه بتعلم كيف يعمّل كومبايلر جافاسكربت لن يهمه مثل هذه النقاشات.

كما يتضح من عنوانه يناقش الكتاب في فصليه الأول والثاني العبارة
this
ويوضح كيف يتحدد معناها وفق أربع قواعد دقيقة بترتيب مُعيّن (الفصل الثاني تحديدا)

الفصل الثالث كان مفيد للغاية وتحدّث باسهاب عن خصائص الكائنات في جافاسكربت، بدون إسهاب أو الكثير من النقاشات الجانبية. خلافا الفصل الرابع الذي خصصه لمناقشة من يحاول استخدام الكلاسات ضمن جافاسكربت، حيث كان الفصل مُسهبا للغاية ومملا بعض الشيء للسبب الذي شرحته في الأعلى.

في الفصل الخامس يبدأ بشرح الـ
Prototype
وكيف أن استخدام الكلاسات في جافاسكربت هو في حقيقة الأمر استخدام لل
Prototype
ولكن مع الكثير من الإملاء والكثير من المشاكل المحتملة
ليبدأ الدسم في الفصل الأخير والذي يشرح فيه الكاتب أسلوب بديل عن البرمجة كائنية التوجيه في جافاسكربت وهو أسلوب أكثر طبيعية وسهولة ويحقق نفس النتائج بدون المشاكل التي يعاني منها الأسلوب الأول. وهو باختصار إنشاء كائنين يرتبط الثاني بالأول بفضل
Prototype
دون الحاجة لإنشاء كلاس يرث منها كل من الأول والثاني، والذي يعتبره الكاتب كما أسلفت إملاء برمجي في ظاهره برمجة كائنية التوجيه وفي حقيقة الأمر مجرد استخدام خاطئ لسلسلة ال
Prototype

في ملحقه يذكر الكاتب أسباب إضافية لعدم استخدام الكلاسات لاسيما وفق إملاء
ES6
Profile Image for Jon Jones.
88 reviews1 follower
October 21, 2019
All books in this series are essential for any JS developer to read. The book explains how Javascript borrowed concepts from other programming paradigms even though they are different.

The prototype object is created for example, even though it is linked to a 'class' is instantiated, in reality, it is nothing like a how an object-oriented language would define inheritance. Class creation works more like functional chaining.

One of the main takeaways I learnt was that Javascript works in a strange way became how it is compiled. It uses lexical tokenising, this way of processing is why javascript has lots of intricacies.

This `this` portion clearly outlines the criteria and priority JS engines use to determine a particular function's call site or context, which in and of itself is enlightening.
Profile Image for Mark.
519 reviews83 followers
March 6, 2018
Very detailed and insightful. Highly recommended for anyone wanting to know JavaScript well. (If you just want a brief intro, this is likely too detailed.) FOR EXAMPLE: If you want to understand the two ways of using "this" (binding) this will help you understand. Kyle also describes the binding of super in the new definition of JS for even deeper knowledge.. the combination can cause strange behavior if you're not aware of these things). ANOTHER EXAMPLE: is the great descriptions of how prototypes work and causes cumbersome (and at times fragile) implementations of class patterns. Kyle also describes the detailed changes brought in with the newer class definition (ES6) and the benefits and possible drawbacks. Thanks Kyle!
Profile Image for Hưng Đặng.
129 reviews71 followers
December 4, 2018
For sometimes, I have heard that JS is not designed for OOP and the application of this programming structure is somehow forceful on the language. This book strongly criticize this practice and although the instroduction of ES6 has greatly improved this situation of conflict, it is not enough. The author proposes another alternative which is OLOO.
Right now when I am working, the practice of OOP is everywhere and the book warns that this style of coding would lead to some sophisticated bugs when the project reach a certain scale.
Not trying all the code example of this book makes me feel guilty. Maybe I should go back to it sometimes to have a better understanding of the subject.
Profile Image for Joshua.
66 reviews4 followers
June 11, 2020
A deep dive into “this” and Objects, along with a different programming style to harness the power of object delegation in JavaScript. And you know what? This is exactly the kind of information I’m looking for, in terms of skill mastery. When I started picking up libraries and refactoring code, it seemed classes were the way to go. In my lack of experience with JS, however, I failed to recognize there are no classes in JavaScript. This book clearly and succinctly breaks it all down and provides a far more relevant approach to writing in JavaScript. 10/10, I highly recommend.
3 reviews
July 22, 2021
For sure, I am totally inclined to use OLOO. It seems very powerful, cleaner syntax and easier to read.

Well, since I'm still quite new at programming and I'm learning the basics of javascript this book is really hard sometimes. The entire book is way more complicated than Scopes and Closures and I struggled at the most part. I've seen myself many times coming back to this page so I could understand some concept again. I still don't quite understand some of the things, specially the final examples. I will have to come back to it and keep studying it.
Profile Image for Victor.
355 reviews6 followers
December 9, 2017
As always, love his book. He has really strong opinions of oop in JavaScript. Initially I was resistant to his opinion, but after digesting for a while, I understand why he said what he said and broadens my mind to other paradigms, namely oloo.

At some parts he may go a little technical but it’s worth it. I can now say I have a much better understanding of this and how prototype chains work in JavaScript.
Profile Image for De Ville Weppenaar.
7 reviews
September 17, 2018
Kyle speaks to me in this instalment of YDKJS. I never felt 100% comfortable using languages that promote OOP design patterns as the only viable option to structure applications. I really love his approach to explaining the pitfalls of this approach in JS, and explaining that it's like "swimming against the current". Rather use the prototype mechanism as it was intended, namely Behaviour Delegation.
Profile Image for Austin Lords.
4 reviews
November 10, 2019
Great info! Starting to feel outdated

Most examples are written in pre-ES6 syntax which feels very outdated at this point. I felt like I was learning “extinct” syntax at times, then Kyle would explain “actually its different in ES6 so be aware of that”. ES6 feels like an afterthought, which explains why Kyle is working on version 2.0. Kyle does a good job explaining the nuisances of the language, but this book is starting to age.
19 reviews
Read
February 27, 2020
This brilliant book clearly and precisely shows what js objects are really are. Before I read it I found it very tricky to argue about inheritance and prototyping in JS. Now the main JS paradigm, which is not classic object-oriented appoarch, is crystal clear for me. So i would definetely advise to read the book for newbies and for experiences professionals who have some doubts about foundation concepts of the language.
Profile Image for Colin Jones.
Author 1 book103 followers
June 1, 2019
Great explanations on `this` that may actually stick this time! The end got kind of ranty on how OO was Bad and prototypal model is Good - much of it seemed either misreprenting or just plain wrong. Kind of a big letdown. See https://github.com/getify/You-Dont-Kn... for more details.

But still 4 stars for thoroughly covering the language features that I was looking to pick up here.
1 review
December 6, 2020
books that are written solely by Kyle are very well written. but books that have more contributors just lowered the quality especially "this & object prototype". constantly referring to previous chapters. making very stupid jokes.

you just can feel in the lines that some non-native writers worked on that part. Their more elaboration just made the book a mess
Profile Image for Dmytro Chasovskyi.
89 reviews
May 5, 2017
It is a great book in a series. Helps to view on JS from a different angle. I highly recommend this book for all people who tightly coupled with OOP principles. It may change your overall vision dramatically, at least, on JavaScript.
Profile Image for Ryan Day.
31 reviews
July 12, 2017
I've never read a book about JavaScript like this. Simpson puts aside everything you've learned about JavaScript over the years and digs into the spec to find out how the language really works. You Don't Know JS makes JavaScript feel like a new and exciting language again.
Profile Image for Anh Tran.
65 reviews31 followers
November 28, 2020
Kyle Simpson explained this so simple and the difference between "OOP" language and Javascript. You might understand why people said JS doesn't have OOP. Btw, You don't know JS series provides the foundation for your web development career path. I highly recommend it.
Displaying 1 - 30 of 81 reviews

Can't find what you're looking for?

Get help and learn more about the design.