get test1() { //getter function
//something
}
test2() { //normal function
//something
}
Inside render what is the difference between “get function ( {this.test1} ) and normal function ( {this.test2()} )” calling? And which is the best practice when we want to call a function inside a render by default?
We are using getters to add extra logic to properties before getting their values, say you want to format these values before getting them or something like that.
The getter method will execute when you want to get this value with dot like student.name, it will return your getter return’s value.
that’s why we don’t use () here because your getter method is executing when you want to get the value by dot.
=========================================
using a normal function to get a variable is like any function you will need to call it to get its return. that’s why we are using () here
=====================================================
when should you use get keyword vs using a normal function(method) as a getter:
every method has a benefits, get keyword affect dot.
but normal function will not affect the dot sign so you will still able to get the original value with dot and the formatted with your function call.
you need to know both tools so you can use any of them when you need them.
and please, there is a tool in the forums to format your code to make it more readable, I think you don’t know this tool. You see how it’s really useful to know as many tools as you can?