Тёмный

What is __proto__ ? | Javascript Prototypes Tutorial 

Dave Gray
Подписаться 343 тыс.
Просмотров 44 тыс.
50% 1

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 131   
@mrinalroy6938
@mrinalroy6938 2 года назад
Every video of Dave is a ton of clarity even for the concepts which are esoteric. Thank you Dave !
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
You're welcome!
@kuehling83
@kuehling83 9 месяцев назад
I watched 6 or 7 videos on this, and this one was BY FAR the clearest. Such an excellent use of simple, relevant examples... and clear precise explanations of a topic that can be confusing. Before watching, why syntax differences in syntax - this video clarified there was an dated/current way to doing the exact same thing! Thank you so much!
@hosamgnaba3205
@hosamgnaba3205 2 года назад
my friend, these advanced topics are hardly ever explained this well on youtube. great work
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Glad it was helpful!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Javascript Prototypes - Prototypal Inheritance and the Prototype Chain - are topics that may come up more as interview questions than when you are really writing code. That said, the more you know about Javascript, the better. Also, ES6 Classes are the "syntactic sugar" that keeps the prototype chain and ___proto___ "under the hood". This tutorial takes a look at the modern approaches, but also, it takes a look at what is going on "under the hood" with Javascript prototypes. If you are interested in learning more, check out my Advanced Javascript Concepts playlist here: ru-vid.com/group/PL0Zuz27SZ-6N3bG4YZhkrCL3ZmDcLTuGd
@aeronwolfe7072
@aeronwolfe7072 Год назад
man... i just absolutely love how clear, and precise, and detailed this advanced Javascript playlist is. thanks again for making these!!! I am not going to name the OTHER one whenever I recommend Javascript videos to other people, I only recommend 2 channels on youtube, and THIS IS ONE!!!!!! GREAT CHANNEL for anyone trying to go further!!!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad you like them! And thank you for the kind words! 🙏💯🚀
@aeronwolfe7072
@aeronwolfe7072 Год назад
@@DaveGrayTeachesCode you are so welcome. i'm watching this advanced playlist multiple times. i freaking love javascript~!
@konstantinospascal1892
@konstantinospascal1892 3 года назад
This topic finally clicked for me when I realized that "__proto__" and "prototype" are literally the same thing. We have the actual object constructs and then references to them making up the chain. But it's so tricky at first with these terms. Great video as always!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Thank you! Yes, I thought the comparisons of ___proto___ and prototype might help. I appreciate the comment! 💯
@hulkaroyj.4960
@hulkaroyj.4960 2 года назад
Really want this to click for me too, but how can they be the same when an object/array can contain both as separate props? As in we’d see “[[Prototype]]” and “__proto__ “ within that [[Prototype]] in an object/array
@konstantinospascal1892
@konstantinospascal1892 2 года назад
@@hulkaroyj.4960 [[Prototype]] and __proto__ are 2 names for the same thing. If i am not mistaken, accessing and manipulating the prototype of an instance with __proto__ is considered unsafe and is deprecated in some browsers, you should be doing it with Object.getPrototypeOf() and Object.create(). Some browsers will display [[Prototype]] while others __proto__, but they are the same thing, and even in the browsers that display the former, you can use __proto__ in your code to access it. Unlike those two, "prototype" is pretty universal and that's an object attached to a Function/constructor as a property. When that constructor is used for instantiating with the new keyword, the instance will get a __proto__/[[Prototype]] property that is a reference pointing to the prototype of its constructor, this is why __proto__ of instance === prototype of constructor. literally the same object, same reference.
@hulkaroyj.4960
@hulkaroyj.4960 2 года назад
@@konstantinospascal1892 I see, thank you for explaining in depth!!
@jhessyOliveira
@jhessyOliveira Год назад
I created a function here to check some things and the result made me really confused. The [[Prototype]] points to the base Object, but __proto__ points to the base function, and only __proto__.__proto__ points to the base Object. Can you explain that? You said they are the same, but that was not the result
@tieTYT
@tieTYT 9 месяцев назад
I don't stick to one programming language so I plan to come back to this video every time I need a refresher. Really well done. The pacing was great and it was comprehensive.
@juliettetworsey3060
@juliettetworsey3060 2 года назад
I needed a refresher on JS prototypes and this was the perfect explanation. Thanks!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Glad it was helpful! 💯
@yatin1370
@yatin1370 Год назад
I have gone through his video couple of times and it kept getting clearer and clearer. This helps a lot for improving my fundamentals. I am surprised how simple you made everything!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad to hear this!
@rgchroniclestv
@rgchroniclestv Год назад
I always go back to this video everytime i do a refresher on closure. Thank you 😊
@quietcorner5989
@quietcorner5989 Год назад
Dave you are a Good Mentor from who I learned a lot of things , I always recommend your tutos to all my friends .I can't beleive that these leesons are free of charge.Thank you man
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You are very welcome!
@focusiam2027
@focusiam2027 Год назад
Dave, you're just amazing, you explain everything so clear. Thank you so much!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're welcome!
@zenguitarankh
@zenguitarankh Год назад
I went through about 5 other videos trying to get an explanation on this in a way that I understood....then saw this....the guy with the EVH Frankie in the back. "I bet this guy is going to explain it in a way that makes sense to me" and I was right. From one player to another. Thanks man.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're welcome! 🎸🎸
@Ii-fo8pq
@Ii-fo8pq 2 года назад
Wow I wonder why this channel got very less subscribers people are really weird this channel deserve a million subs just for this video .
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Thank you for the kind words! It keeps growing every day! 🚀
@pajamaguru5315
@pajamaguru5315 Год назад
Beautiful EVH guitar in the background! Immediate respect as soon as I clicked on the video \m/
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you!
@tonytodd7011
@tonytodd7011 Год назад
Thank you very much Dave, for your great advanced topics for JavaScripters! Much easier to understand than what I have read and watched before!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're welcome!
@sithutun688
@sithutun688 Год назад
I love you Dave Gray.Your course helps me a lot please do more advanced course like this.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you for the request!
@callumacourt2727
@callumacourt2727 Год назад
Only tutorial that enabled me to understand this. Thank you very much!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad it helped!
@676005ga
@676005ga 2 года назад
I really likes this series and have learned a ton. Thanks you for making these great content!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Glad to hear it! 💯🚀
@nikoman71326
@nikoman71326 Месяц назад
amazing explanation as usual! thank you!
@blakeclark8622
@blakeclark8622 3 месяца назад
Super clear explanation. Thanks!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 месяца назад
You're welcome! Thanks for the support!
@iambabyr0o
@iambabyr0o Год назад
This explanation is BEAUTIFUL! Thank you!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're very welcome!
@kostiantynkarzhanov9216
@kostiantynkarzhanov9216 Год назад
Awesome! Thank you so much for this very well explained and easy to understand tutorial! 💛
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're very welcome!
@fdj1966
@fdj1966 3 года назад
Thanks for the clear and easy explanation on confusing subject !!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
You're welcome 🙂🙏
@AkimboFennec
@AkimboFennec Год назад
Best explanation of prototype ever
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you!
@saitejagatadi9711
@saitejagatadi9711 2 года назад
I would rate this video as one of the greatest video I have watched in recent times. Your explanation skills are awesome Dave.. It's like content is being injected to my brain 🧠 I love your channel in such a way that I have subscribed to your bell notifications which is something I usually won't do for any other channels 😉😜😛😁
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Thank you for the kind words! 🙏💯
@gilmoretj
@gilmoretj Год назад
Hi Dave, Another excellent video and superb explanation of the role and difference between the __proto__ and prototype properties. One think I think some viewers might query is why the accessor functions are preferable to using the __proto__ property directly? You did explain the rules and limitations of setting the __proto__ property but do the accessor functions provide and safeguards? Regards, Tracy
@ahmad-murery
@ahmad-murery 3 года назад
I remember that I used to create a function to represent a model then I use prototype to extend it or tweak it so that any new instance of this function will have new extended properties and methods, of course inside the function will make use of "this" keyword to assign and access properties/methods For the new ES6 classes, calling super() from within the constructor of extended class might not be necessary when the parent class constructor is not defined, but it's still very recommended to call super() because: - most of the time you don't want to check the parent class to see if its constructor is defined (especially when the class is not yours) - you may need to add a constructor for your parent class and then forget to update its extended classes. so calling super() doesn't hurt but not doing so might causes you some headache similar to reading this comment I guess 🤔 Thanks Dave you always bring great topics
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
😂 Good joke Ahmad... but I always enjoy your comments. Thanks once again! 🙏
@ahmad-murery
@ahmad-murery 3 года назад
@@DaveGrayTeachesCode 😎😁
@dardaC137
@dardaC137 2 года назад
This tuts make my JS journey much more easier . Thanks a lot . Can u please make a tuts on iterators and generators please.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
You're welcome, Abu! And great request! I look forward to doing that! 🙏🚀
@aungthiha628
@aungthiha628 Год назад
pure gold.
@kryoleks
@kryoleks Год назад
Thanks a lot for the straightforward content!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad it was helpful!
@aleksandarmihaylov6884
@aleksandarmihaylov6884 Год назад
best explanation ever
@olivierabilio8470
@olivierabilio8470 7 месяцев назад
Merci pour ce cours !
@MigalYaroslav
@MigalYaroslav 2 года назад
I like your explanation. Thanks from Ukraine.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Thank you! And hello to Ukraine! 👋🌻 Fun fact: I'm from Kansas and the sunflower is our state flower as well as your national flower. 🌻🌻🌻
@bigbadcatbigbcy2933
@bigbadcatbigbcy2933 6 месяцев назад
video helped a lot thanks
@27sosite73
@27sosite73 5 месяцев назад
thank you thank you thank you thank you
@DJ_Unh0ly_Hardcore
@DJ_Unh0ly_Hardcore 2 года назад
This was really well explained thanks.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
You're very welcome! 💯
@MEGZ365
@MEGZ365 3 месяца назад
thank you sir i am pleaser for you✨
@vuejs1
@vuejs1 Год назад
Truly mindfuck. I love it😂
@robx_001
@robx_001 2 года назад
so much new info. Great!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Glad it was helpful!
@prudhvichinnam1488
@prudhvichinnam1488 3 года назад
Great content keep doing this
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Thank you! 💯
@rangabharath4253
@rangabharath4253 3 года назад
Awesome thank you ☺️☺️
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
You're welcome!
@Hariharan0606
@Hariharan0606 Месяц назад
Lovely!
@HIOLLJ
@HIOLLJ 7 месяцев назад
Succinct, incredible.
@kirillholt2329
@kirillholt2329 2 года назад
this is very clearly explained
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
I'm glad I could help 💯
@Marksman18
@Marksman18 2 года назад
This is basically OOP with plain JS? Didnt know you could do that :)
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Yes it is! 💯
@alimohammadi1517
@alimohammadi1517 2 года назад
Legendary video thank you sir
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
You're welcome! I'm glad it helped! 🙏💯
@giorgikirvalidze394
@giorgikirvalidze394 2 года назад
Amazing content
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Thank you, Giorgi! 🙏
@soltiscd
@soltiscd 3 года назад
Really good discussion.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Thanks! 🙏
@Albert_Hall
@Albert_Hall Год назад
🚀🌍🌠 This channel is from my very top list. Whenever I listen smth, I like it 🍯
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Happy to hear that!
@dopetag
@dopetag Год назад
Dave, what do you think about this statement from mozilla docs about Object.setPrototypeOf()? Should we still use it? "Warning: Changing the [[Prototype]] of an object is, by the nature of how modern JavaScript engines optimize property accesses, currently a very slow operation in every browser and JavaScript engine. In addition, the effects of altering inheritance are subtle and far-flung, and are not limited to the time spent in the Object.setPrototypeOf(...) statement, but may extend to any code that has access to any object whose [[Prototype]] has been altered. You can read more in JavaScript engine fundamentals: optimizing prototypes. Because this feature is a part of the language, it is still the burden on engine developers to implement that feature performantly (ideally). Until engine developers address this issue, if you are concerned about performance, you should avoid setting the [[Prototype]] of an object. Instead, create a new object with the desired [[Prototype]] using Object.create()."
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I think Mozilla / MDN is a great source for accurate and up-to-date information. While many in the past have said they need to know about __proto__ during interviews, tech is always changing and I made this video around a year and a half ago. The concept hasn't changed and I think the video is still helpful, but reviewing any info MDN has to share is a good idea. 💯
@mrgreen3749
@mrgreen3749 11 месяцев назад
when i do this 'a ${this.species} is walking' the whole thing is a string and it dosent place the value in where the $ is. how do i fix?
@marcelhess5989
@marcelhess5989 4 дня назад
You have to use backticks instead of quotation marks to wrap whole string. Its called template literals.
@minds_unchained
@minds_unchained Год назад
Awesome thanks! Why `_proto_ ` is not working now?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You need 2 underscores on each side.
@doniaelfouly4142
@doniaelfouly4142 4 месяца назад
thanks
@jiweihe3413
@jiweihe3413 2 года назад
Thanks for the helpful video! Does "__proto__: musician" mean guitarist inherits all props and methods from super class musician?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
You're welcome! Can you provide a video timestamp to reference your question? I made this nearly a year ago and do not remember each example.
@jiweihe3413
@jiweihe3413 2 года назад
@@DaveGrayTeachesCode thanks for reply! It refers to 6:30.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
@@jiweihe3413 not only musician, but notice it also inherited the alive property from Person which is the parent of musician. Of course, musician inherits this as well so you could say it is passed down the chain.
@xx_kyon
@xx_kyon 9 месяцев назад
You should change your name to David Grayt after this class
@doniaelfouly4142
@doniaelfouly4142 Год назад
Thanks
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Welcome!
@borakayalar
@borakayalar 2 года назад
Perfect
@mdtowhidulislam5260
@mdtowhidulislam5260 Год назад
# An Object can only directly inherit from one object - this statement I am not understood. can you please say me in more easier way.
@mertma52
@mertma52 2 года назад
Minute 2:42, when I open the object, it says [[Prototype]] twice. And with you it says __proto__ why is that?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
It has been over a year since I made this. Chrome may have had an update that presents this differently. I just checked. Expand the 2nd Prototype you get and you will see the __proto__ further down in the expanded list.
@user-tt6nc6mo7k
@user-tt6nc6mo7k 3 года назад
So at 10:00 on line 29: luxuryCar.seatMaterial = "leather" you are using the setter that starts on line 22 correct? But the setter seems to impy that it should be called as a method with the desired material passed to it as an argument. i.e instead of luxuryCar.seatMaterial = "leather", it should be luxuryCar.seatMaterial("leather") when you use dot notation luxuryCar.seatMaterial = "leather" why does it not create a property called seatMaterial and set its value to "leather"? How does it know to execute the setter method?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Good question! This is through the use of the keyword set in the object. Here is the reference from MDN with more examples: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set
@AmitKumar-cp6mx
@AmitKumar-cp6mx 11 месяцев назад
happy to see that someone had notificed this
@sigmiami
@sigmiami 3 года назад
I wanted to watch this to distract my mind but my mother in law just passed yesterday from lung cancer and object "alive" got me... I hope to come back to this... pain sucks
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Sorry for your loss.
@sigmiami
@sigmiami 3 года назад
@@DaveGrayTeachesCode thank u
@longingbydesign
@longingbydesign 3 года назад
If the musician in your first example is alive and playing, why can't we hear their music?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
It may be beyond the scope of this tutorial, but it could happen: developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
@djhi-tek9249
@djhi-tek9249 6 месяцев назад
Some people born rich, others had to learn this...
@mo_i_nas
@mo_i_nas 3 года назад
Dave, everything made sense for me up until you started explain ES6 classes. You kinda skipped over very important concepts that I'm still trying to grasp. What is 'class'? what is 'extend'? what is 'constructor'? what is 'super()'? and yes, they are basically what you explained earlier in the video, but I guess what I'm trying to understand is what's really happening in constructor function, or what is really happening when you call super() And of course, it goes without saying, your work is very appreciated it, thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Thanks for asking Mohamed. To go over the basic foundational knowledge of JS classes, I'm going to refer you to my separate classes tutorial: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5fmifZZeJJ4.html To expand on the brief examples of "extend", here is the MDN link: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends and here is MDN for super, too: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super I hope that helps!
@AmodeusR
@AmodeusR 2 года назад
That extends (no pun intended) the objective of this class. All of it will be answered if you study about Javascript Classes. The topic of this video is about the Prototype object, so that's why he didn't explain such things.
@ua2894
@ua2894 8 месяцев назад
i didn't know cars had hwheels!
@longingbydesign
@longingbydesign 3 года назад
Unfortunately you're using structurally different examples when comparing functional syntax to class syntax. Your function-based example does not involve inheritance, which is what I'm really having trouble wrapping my head around. Can you show the exact same thing with Vehicle and Motorcycle in funtion-syntax? The only way I got it to work so far is using what Nicholas Zakas calls contructor theft, that is, doing Vehicle.call(this) in the Motorcycle constructor, and even that is unclear to me.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
I wouldn't say it is unfortunate. Abstract your thinking to properties and methods and not what their names are. That said, good question and good job on being inquisitive while wanting to take this to the next level. I gave examples of ES6 classes last and did not show an equivalent way to create an extended object with a function. It is a different approach because functions do not use inheritance like ES6 classes do. Functions can use what is called "composition", and you can pass a created object into another function as a parameter to avoid repeating all of the property and method definitions. I'm planning on a tutorial next week on functional composition. That said, I completed your request and you can see an example of functional composition for Vehicle and Motorcycle in this gist: gist.github.com/gitdagray/40d7117dcea6ea1274cd68f8204a3896 More on functional composition coming soon. If you would like a more fundamental understanding of ES6 classes, view my dedicated tutorial here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5fmifZZeJJ4.html
@MariaKomlevski
@MariaKomlevski Год назад
@jesuswalks1101
@jesuswalks1101 3 года назад
Nice voice)
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 года назад
Thank you! 🙏
@forheuristiclifeksh7836
@forheuristiclifeksh7836 Месяц назад
1:48 musician.__proto__=person;
@Ronifromearth
@Ronifromearth 2 года назад
thanks
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 года назад
Welcome!
Далее
JavaScript Prototypal inheritance - Tutorial
15:29
Просмотров 79 тыс.
STOP Using Classes In JavaScript | Prime Reacts
14:02
Просмотров 241 тыс.
Visually Understanding JavaScript Prototypes
14:58
Просмотров 54 тыс.