Is it possible to create a private "function" (method) in the TypeScript class? Suppose 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); } }
What when compiling is converted 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 in closure, but not on the prototype? In essence, does this make the whisper function open at compile time?
typescript
Richard Jun 04 '13 at 13:41 2013-06-04 13:41
source share