Those who say, must not use the “_”, for them, here is some code from TypeScript site:
class Employee {
private _fullName: string;
get fullName(): string {
return this._fullName;
}
this._fullName = ......
}
Same question on Stackoverflow, you should have a look on it, especially the answer.
For the time being, if accepted, we should not use _, then what are other better ways?
Let’s take your example of email, if we will not use _ then, we will come something like this:
member: to, get/set: emailTo
member: from get/set: emailFrom
might be you can think some better name, but every time you need to think, which is not very common in the developer world!
Using _ and the same name for a property is easy to check the code otherwise we will be keep mapping which property to which member.
BUT: If you have been forced by your lead at your company then you can use $
for member and property without it; not a rule but easy way:
class Employee {
private fullName$: string;
get fullName(): string {
return this.fullName$;
}
this.fullName$ = ......
}
The Choice Is Yours!!!