JavaScript Classes #3: Static Methods - JavaScript OOP Tutorial

preview_player
Показать описание
In JavaScript you can define "static methods" or "static functions" which are functions that are defined on a class but do not actually require an instance of that class to be created.

In most cases, static methods are "helper methods" or used for creating instances of that class.

In this video I take you through a simple example of how you can define static methods on a class - we create a method used to compare two instances to give a result.

For your reference, check this out:

Support me on Patreon:

Follow me on Twitter @dcode!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

Thank you! Simple, direct explanation which is perfect for any beginner who is still starting out :)

jewels
Автор

Thanks brother, I've been trying so hard to understand this concept but you broke it in simple pieces.

vishvsalvi
Автор

Thanks for the clear explanation man, was really helpful

tunafish
Автор

Thank you! Simple, direct explanation

saikrishnakalangi
Автор

Nice explanation, very easy to understand. Thank you

SamuelCoupland
Автор

Thanks a million for making a video about this. <3

hyfytale
Автор

May I ask what keyboard are you typing on? And thank you for the video, the first 30 seconds was already good at clearing some things up for me.

christianlewis
Автор

Very clear explanation, I'm grateful.

ladiesman
Автор

explaining a very good use case great!

kimse
Автор

wow, this is the best video ever! Liked and favourite! :)

el
Автор

Thank you!!! your explanation and practice is great

willypratamaa
Автор

Hey Dom,
Great videos. Thank u.
It would be great if you could make a video about the using of .prototype in inheritence.
Thank's a lot.

eyalshnitzerful
Автор

Awesome. Now I get it. Thank you so much.

alicefraser
Автор

This is so helpful! Thank you for a great explanation.

zacmackey
Автор

But what's the difference between static methods and a normal methods in classes? Help!

j.villasmil
Автор

Thank you so much.It is really helpful.

shivarammuthukumaraswamy
Автор

I finally figured out the ways to use static methods, but still can't imagine easily when should I use that in real life :0

juanyang
Автор

Thank you so much. Very very clear and helpful.
What's the common usage of this static method in the more complex cases?

jamesdong
Автор

Would it be easier to have a class of utility methods instead of including them in the square class? If “this” is not ever used, what benefit do we have of including them in the same class?

kevingreetham
Автор

Good explanation as always! Thanks!
But I'm not so sure if this a good approach from a more "abstract" point of view. IMHO properties "are" things with a value. Functions / methods in OOP "do" stuff with properties and the function's parameters. I know that at the end of the day it all boils down to the same in Javascript. But from a working programmer's point of view: I do not see the added value. It works but does not really help to keep your code "clean". But I appreciate all comments about potential benefits. Always willing to learn ;-)

montebont