Why doesn't TypeScript encapsulate the private variables?
Given the following TypeScript:
private engine: string;
constructor(engine: string) {
this.engine = engine;
}
start() {
console.log('Starting engine ' + this.engine);
}
}
var car = new Car("Fiat");
car.start();
When I compile I get the following JavaScript:
var Car = (function () {
function Car(engine) {
this.engine = engine;
}
Car.prototype.start = function () {
console.log('Starting engine ' + this.engine);
};
return Car;
}());
var car = new Car("Fiat");
car.start();
The engine
variable is public. Why doesn't TypeScript produce something more like:
var Car = (function () {
var _engine;
function Car(engine) {
_engine = engine;
}
Car.prototype.start = function () {
console.log('Starting engine ' + _engine);
};
return Car;
}());