Reputation: 607
In a project where I am working(Vue.JS Project) I found in so many places they have used this 'get' before the function, but I am not clear yet why do we need that. I have added one function with this get:
get dataNotYetArrived(): boolean {
return justAnExample;
}
It will be helpful if someone can explain this to me. Thanks
Upvotes: 2
Views: 1576
Reputation: 15966
It's the getter
syntax. It's a Javascript feature that assigns a function to be executed when accessing the property -- which is useful when you want the property to return something dynamic, rather than a static value. So:
get someProperty() { ... }
executes the function someProperty()
when you access myInstance.someProperty
.
More here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
Upvotes: 2