Typescript "private" access modifier

Asked

Viewed 263 times

2

In most examples I find Typescript I see that the class attributes do not use the access modifier private. It is a matter of design or there is some difference in operation compared to Java?

export class Aluno {
    codigo:number;
    nome:string;
}

1 answer

3


Let’s agree that the term attribute is wrong, you mean field . Typescript has its public members by default, so in the absence of something explicit the access is general.

The fact that you don’t see them wear private It’s just a coincidence, it’s possible. There’s a chain that doesn’t follow this "object-oriented" fashion that everything has to be private, even if people don’t even understand why they’re doing it. TS is a language of script, As the name says, then it is much less necessary to follow object-oriented rules than in other languages. But if you have a good reason you can establish that any member is private.

It’s a little different from Java, which by the way people think is private by default and is not.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.