You can’t get very far in JavaScript without dealing with objects. They’re foundational to almost every aspect of the JavaScript programming langua...
For further actions, you may consider blocking this person and/or reporting abuse
This is a great and thorough explanation. I wish I could flex my JS more but I just don't get the opportunities. All I can do is read articles nlike this and hope it stays in my head until it might be needed.
Funny enough but true
I feel like I just watched a Douglas Crockford lecture in reverse!!
This is a great explanation, but just to weigh in from Crockford's perspective, who's very skeptic about both
class
andnew
:class
to JS is actually a step backwards. In my view, it is a misnomer because you could've had the same behavior using the wordprototype
(but sadly that wasn't a reserve word... I'll assume that's the reason why they went with class).new
keyword to create the pseudo-classical inheritance mode, which should've never been there.new
operator is that if you create a function that requires it but then you forget to type it in, you will pollute the global object instead of creating a new one. That's the reason why constructors are capitalized by convention, so people get used to expecting anew
there.Object.create
, the method that provides the true prototypical inheritance, wouldn't be added until ECMAScript 5. Sonew
precedes it by a decade, I believe.But, as I said, this was a very thorough explanation. Thanks!
"So when you try to access leo.prototype, leo doesn't have a prototype property so it will delegate that lookup to Animal.prototype which indeed does have a constructor property. If this paragraph didn't make sense, go back and read about Object.create above."
I think you meant 'leo.constructor' + 'constructor property'? :)
Perfect.
Good article, thank you!
Very good presentation
This is an excellent post on explaining prototypes!! Thank you for sharing!
One of the best article I have read about the JS object and how constructor and prototype chain works..thanks Tyler for this article.
Great article, perfectly explained. I also learned a lot today ! Thanks !
Awesome article! A great explanation of often misunderstood concepts in JavaScript.
Cool! Thanks for this post. I am subscribed to your newsletter. All the material is always very helpful.
Good article. Learned a lot today.
Wow... great article, I've been struggling with this till now. Tnx a lot
Really Great, thank you Tyler