Is it possible to create a private "function" (method) within a TypeScript class? Let's assume we have the following Person.ts
TypeScript file:
class Person {
constructor(public firstName: string, public lastName: string) {
}
public shout(phrase: string) {
alert(phrase);
}
private whisper(phrase: string) {
console.log(phrase);
}
}
Which when compiled is being transformed to the following:
var Person = (function () {
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.shout = function (phrase) {
alert(phrase);
};
Person.prototype.whisper = function (phrase) {
console.log(phrase);
};
return Person;
})();
Observations
I was expecting the whisper
function to be declared within the closure, but not on the prototype? Essentially this makes the whisper
function public when compiled?