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
An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
How’s it going, I'm a Adam, a Full-Stack Engineer, actively searching for work. I'm all about JavaScript. And Frontend but don't let that fool you - I've also got some serious Backend skills.
Location
City of Bath, UK 🇬🇧
Education
10 plus years* active enterprise development experience and a Fine art degree 🎨
The getter is just another syntactic-sugar to reach into objects. It's equivalent to using the dot notation like person.name but it provides the ability for you to:
watch when objects are being accessed (in general, this is how Vue.js detects changes)
dynamically create return objects
It enables you to do both of those without changing the syntax.
An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.It might just be better to create an object straight up in that instance.
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.