In this video, I examine the concept of “Prototype” in the JavaScript programming language. I look at how you can attach methods to objects via prototype (for both objects of existing JS types or your own). I also discuss the “prototype chain” and prototypal inheritance.
Support this channel on Patreon: https://patreon.com/codingtrain
Send me your questions and coding challenges!: https://github.com/CodingTrain/Rainbow-Topics
Contact:
Twitter: https://twitter.com/shiffman
The Coding Train website: http://thecodingtrain.com/
Links discussed in this video:
My Steering Behaviors on the word “Train” video: https://youtu.be/4hA7G3gup-4
Douglas Crockford’s video on prototypes(and many more subjects): https://youtu.be/DwYPG6vreJg
Prototypes on MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype
Source Code for the all Video Lessons: https://github.com/CodingTrain/Rainbow-Code
p5.js: https://p5js.org/
Processing: https://processing.org
For More Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
For an Intro to Programming using p5.js: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
Help us caption & translate this video!
http://amara.org/v/4XSk/
Original source
37 responses to “9.19: Prototypes in Javascript – p5.js Tutorial”
Every now and then I come across your videos randomly. You are by far the best at explaining dry, overly- complex topics. I'm an experienced full-stack developer. I learn something every time time I watch one of your videos. I've taken university courses, professional development training, online subscriptions to e-learning sites. Your approach blows them all out of the water. Clear, fun and to the point. Thank you. I pick up more from you in 20 minutes than I do from a day of reading MDN documentation. Anyone disagrees, I suggest reading https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes, and then watching this video. Cheers.
Did you ever make a video to follow-up on this one discussing further prototype related topics, such as inheritance, polymorphism, classes?
So when working in ES5, it's often good to keep individual properties inside the constructor and to put common methods within the prototype? Javascript seems to have a lot of workarounds needed to implement OOP. Prototypes, this, bind, call etc. It's almost like it wasn't intended to be an OOP language.
Awesome and helpful as always..I really love your teaching…thank you for explaining in such an easy way..
The best moment on the video 18:04. The best part!!!
Hey. I have been watching your tutorials for quite a time now.Some functions are not present in the p5 reference. How do I know about them?
P.S – I like your coding challenges. They are very informative.
You should give lessons more often….you have the teaching-x-factor 🙂
I love your videos keep up the good work
im new to javascript , and im wondering why do you use var instead of let or const ?
Do have recorded the video 2 already?
7:42–9:00, "prototype chain"
—15:33–16:43, "hasOwnProperty()" investigates "prototype chain"
3:44–7:32, I. object property list
10:45–11:20, II. prototype property list/13:17–13:22, "_proto_"/XXX.prototype
—11:37–12:23, how to add functions to property list/_proto_
13:2314:13, III. object prototype property list/"Object.prototype"
Sir. You are a master of your trade
This is guy makes code non boring, you should teach angular damn
Where's the next promised videos about inheritance?
Love this video. It's not very often I go looking for a video on programming theory, and walk away not only understanding the subject matter, but also understanding the usefulness.
Annoying!
04:55 LOL
So, will this change the p5.Vector in the library or is it specific to this sketch only? I guess – library?
i was about 1 week moving from book /video to an other to understand it >>>but finally i understanded it due to you
"thank you "
THANK YOU VERY MUCH
I LOVE YOU
* toLocaleString() method is used for date object, why it is in function prototype object?
please reply me anybody…*
These are the best javascript tutorials * ~ *
Hi The Coding Train. If someone logged into a website built on firebase using login and pass, how would you redirect that user to another page?
This guy has a great sense of humor and it's a pleasure to listen to him 😀 even if that's not your subject.
Telling me not to watch the video in the first 30 seconds earned you an automatic like! I love it!
Can anyone pls explain how to get the js file working on the console? Is this a stupid question?????? please help me im lost
Does anyone have the link to the followup video?
I come from the Java ecosystem and I feel uncomfortable when using 'this' in JS.
//Say user-1 did this
const product1=new Object({
name: 'user-1'
})
Object.prototype.hasOwnProperty=()=>'This is the new function'
console.log(product1.hasOwnProperty(name))// o/p: This is the new function
//Say user-2 did this
const product2=new Object({
name: 'user-2'
})
console.log(product2.hasOwnProperty(name))// o/p: This is the new function
Doubt #1
Ideally user-1 shouldn't have been allowed to add new property to Object object's prototype right ? Because in above example when user-2 wanted to check whether 'name' property exists he is getting different o/p which was set by user-1!!!
Doubt #2
product1.prototype.hasOwnProperty=()=>'This is the new function'
Why is this not allowed ? product1 is an instance of Object, so it is also an object, so even it should have [[Prototype]] property!
TIA.
Very well explained. Thank you
What you explained on the white board helped me understand Prototype better. Thanks.
I love your vids =D
wew mind blown!!! thanks sensei
totally readable function hasOwnProperty on your whiteboard …it's even worse than my handwriting 😀
Thank you so much for this.
incredibly good job
Isn't it kind of static method from Object Oriented Language ?