This post, we will learn how the static keyword works in JavaScript.
First, let's take a look at a simple JavaScript Class.
class Person {
con...
For further actions, you may consider blocking this person and/or reporting abuse
I find it funny that you can now do.
Reminds me of old school college IT lessons.
Ah the good 'ol days
The best part... you will never need to type that out again.
In you're last example, you use 'get' in addition to static. What does that really do? I've seen it a lot and used it a little, but how does it make random() different from a function returns what random(( is already returning
Without the
static
, you have to instantiate the class before you will be able to access the getter.right. I was asking about what the getter is doing in-general. I'm sure it's something, but what?
The
getter
is just another syntactic-sugar to reach into objects. It's equivalent to using the dot notation likeperson.name
but it provides the ability for you to:It enables you to do both of those without changing the syntax.
Getters are usually used to create dynamic properties because it is a function you can write logic e.g you can read value of a property from a file or from database.
It might just be better to create an object straight up in that instance.