In the previous comment, Aaron pointed out that in Javascript, public and private members appear the same, making it impossible to differentiate between them with a method. For example, consider the following TypeScript code:
class Car {
public model: string;
private brand: string;
public constructor(model:string , brand: string){
this.model = model;
this.brand = brand;
}
};
This code is compiled to:
var Car = (function () {
function Car(model, brand) {
this.model = model;
this.brand = brand;
}
return Car;
}());
;
Upon compilation to JavaScript, it's evident that there is no distinction between the model
and brand
members, despite one being private and the other public.
To differentiate between private and public members, one could utilize a naming convention such as public_member
and __private_member
.