I am trying to rewrite one of my useful JavaScript class with TypeScript.
In my JavaScript class I use closure variable self for implementing private field.
It is useful in event handlers, for example onkeypress, where important to know invoker of event and current instance of my class.
var MyClass = function (valueHolder) {
var self = this;
this.valueHolder = valueHolder;
MyClass.prototype.DoUsefullactions = function (value) {
alert(value);
}
MyClass.prototype.onclickForHolder = function (e) {
var value = $(this).val(); //value from attached input
self.DoUsefullactions(value);
}
MyClass.prototype.GetSelf = function () {
return self;
}
this.valueHolder.onclick = this.onclickForHolder;
}
I can't find how to make what closure variable what will be available for all methods of the class without this.self syntax in TypeScript and make true private members in JavaScript way.