We explore the __proto__ property on JavaScript Objects, and how it relates to the normal prototype. Basically, the .__proto__ property points to the object that the current object actually will use when doing lookups on the prototype chain, while “.prototype” only exists on functions, in case you want to use those objects as constructors
passed to the new keyword.
# Stuff mentioned in the video:
• Full series: Object creation in JavaScript
https://goo.gl/pCt2tX
• Music in the video: Peacock by 7 minutes dead
# I’m also active on:
• Twitter https://twitter.com/mpjme
• Medium https://medium.com/@mpjme
• Quora https://www.quora.com/profile/Mattias-Petter-Johansson
Original source
44 responses to “__proto__ vs prototype – Object Creation in JavaScript P5 – FunFunFunction #52”
Good explanation, thanks
You got distracted by looking up cat pictures. That is a true real world problem for developers today haha.
_proto_ is a function and prototype is an object Underscore is special character on youtube LOL
Thank you so much for this video! It really helped me finally to somehow understand the magic behind _proto_ vs prototype a little bit better! Keep up the good work! Cheers
typeof Object()
"object"
typeof Object
"function"
For the people that still don't get it: https://stackoverflow.com/a/42002749/7593159
funfunfunction, could you do some node.js or advanced js tutorials?
I went to a zoo that only had a small dog.
It was a ….
i thought prototype is an Object, but Function.prototype is a function, Array.prototype is an Array so and so on, Can you please explain !
15:00
This is definitely the trickiest part in programming!
Too many options
I have 99 problems. And __proto__ vs prototype is definitely 20 of them.
this was awesome, and honestly better than the earlier ones. Might be the browser environment and the knowledge build up at this point in the series, but, I think it's a significant improvement.
Hi, So basically, you made it sound like when you use the "new" keyword – you create a copy of an object… and when you use "prototype " or "__proto__" you're essentially making a REFERENCE. I can't really find what the different between a copy of an object (when you use "new" keyword) or a reference to an object(When you use "prototype" or "__proto__"… They practically return the same result… My question here is that when we use copy or reference, are they just for the theoretical purpose, or there's a difference in both… I hope my question makes sense.
That FPS!
Comment for content bump.
exactly what i wanted _proto_ vs prototype is all use cases
so glad for let and const
Now everyone is trying Object.prototype={} . Thanks for the video!
I wish that you made a project to explain OOP much better
I think I watched this Object series 2 or 3 times as a reference.
After about a month, I finally get it. Thank god.
You did a great job explaining the difference to me an now I understand however please don't get a job coming up with new names for javascript 🙂 If you named it like that I would have to stop using the language ;P
Google search for munchkin cats has skyrocketed immediately after this video
Awesome
Thx man, I've just discovered your channel for myself as for guy which trying to switch from .Net world into the JS one. Your videos really help me 😉
What hair pomade do you use? Is there a special one for programmers, for example, that doesn't melt onto the keyboard in hot weather?
every time I watch this I think I totally get it and it all makes sense and yet here I am watching this for the third time!
Great great video! I have learned so much because it's fun watching your videos. My only suggestion is that you use a small whiteboard instead of paper. It seems like an awful lot of paper being used.
Probably the best name convention should be `.prototypePrototype` haha
great vid. thanks!
super useful man! great vid
Why does Function.prototype.proto_===Object.prototype?
Wait, so what's the difference between prototype and this?
_proto_ should not be used commonly as it is a part of javascript engine's internal linking, nice tutorial. well explained.
This guy and Anthony Alicea are the best at describing js oddities.
Tack som fan för de här videona! Du är sjukt pedagogisk, till skillnad från de flesta som försöker lära ut programmering…
Awesome video!
I wrote this piece of code, but don't exactly understand why the results are the way they are –
Number.prototype.square = function () {
let value = this;
return value * value;
}
String.prototype.append = function () {
return this+' JavaScript Rocks!';
}
'hello'.append() yields "hello JavaScript Rocks!"
new Number(4).square() yields 16
var i = 4;
i.square() yields 16.
But,
4.square() gives "Uncaught SyntaxError: Invalid or unexpected token"
The typeof 'i' and 4 is both "number". Kindly explain why this is happening.
Happy Coding!
Kaushik.
Well explained, I will use the pen delegation example when I explain prototype to others. You should do an episode about the difference between changing a property value on the prototype object vs changing it on an object with the same prototype. It also confuses a lot of people.
Hello mpj, even I have worked mainly as a software engineer since 23 years, I consider myself as a beginner and very ignorant developer (especially in JS), but I "stay curiouss' even though. I often refer to you as my "programming Guru"
I appreciate a lot your series and watched Object series from P1 to P5. but I have a st()()pid question:
I don't precisely grasp the differrence between declaring a "method" directly in the function like that;
v1: called "methods defined internally" in this article (http://www.phpied.com/3-ways-to-define-a-javascript-class/)
function Person{ laugh: function{console.log('haha !') }
or like that
v2:
function Person{ }
Person.prototype.laugh = function{ console.log('haha !') }
I am not sure but I think reading previously that with the v1, laugh property will be duplicated every time a new Person object is created while its not the case in v2 because laugh is factorized / delegated to Person.prototype
It also seems that these issues are related with this famous OOP quote 'Inheritance may always be replaced by delegation' (which is illustrated by the "one UML class diagram to rule them all": the class related to itself with a white diamond shape ending edge
Long time ago I've heard about the "Prototype-instance" paradigm (by contrast with "Class-instance"). JS is a Protytope based programming language right(https://en.wikipedia.org/wiki/Prototype-based_programming) ?
Also I've been very interested by AOM (Adaptative Object Modelling) where Classes are just "dynamic objects that can be used as templates for new Objects". I've even wrote a "private-joke" prototype "Single Class Object Model" (https://github.com/terimakasi/scom) to satirize the labyrithine nature of the "deep static class hierarchies" and proposing the extreme opposite with a single class on which methods and attributes are dynamycally defined
Apart from being static, "Class based language" bring another trap: mix two very distinct things:
1. Delegation: factorization (generic reuse) of attributes/methods
2. Typing: categorize objects by common profile (same behavior and appearence). Keeping in mind that an object may generally belong to multiples types (ex: a man may be both a Father, a Brother, an Employee, a Friend, an Artist, a Chess player etc)
Thats why I globally hate Java:
– Interfaces are great but Classes are crappy (IMHO): I've for a long time been disturbed by these "anonymous classes", then discovered that it was mainly a way to hide the dys-functional nature of Java by encapsulating a function in a class. Because function are not first class citizens in Java (which has been fixed with Java successors like Scala)
For this reason JS after all may be a better OOP language by encouraging delegation over inheritance and at the same time "saving us" with the crappy "REAL class" entity
I've heard people pronounce _proto_ "dunder proto".
OMG, you are the first guy who explains this _proto_ and prototype thing so clearly. Even better than my teacher. Thank you!
ahahaha "shiatsu" is a type of massage you can get! Lol
You can also check that Object is a function by typing:
> typeof Object
< "function"
Great channel, thank you!
each protoss is create from prototype
protoss are connected by khala(in javascript, it's Object), so they can share the wisdom and power.(Object.prototype functions)
_proto_ means the protoss's hair, notice is can be cut, that mean reassign.
https://youtu.be/yqiGKjhjemk?t=1h44m20s
every time I saw prototype, I relate with protoss…. what the hell is that…
https://www.youtube.com/watch?v=yqiGKjhjemk