I'm fairly experienced programming but quite new to TypeScript.
Trying to use it with jQuery and immediately ran into the 'this' issue with callbacks (such as $(document).ready.
Using $.proxy() is one way to go, but using TypeScript's arrow (lambda) functions seemed much better. But I only see them used as expressions — that is the entire function is defined inline. I would like to be able to set up arrow functions that could be called as methods of my class, something like (in pseudocode):
class Something {
constructor() {
$(' nav li').click(this.menuClick);
}
private menuClick (and this would be an arrow function to preserve 'this')()=>
// it would call this.anotherMethod()
// plus lots of other things so it won't easily fit inline
private anotherMethod():void {
// do something on the menu click, several lines perhaps,
}
}
I come from an OOP background in AS3, and that's how I was able to do it -- 'this' was readily accessible or it was clear how to access it. I'm keen to use TypeScript to get past the OOP hurdle I'm having with Javascript plain -- but it seems cumbersome (to me) to have to proxy all the jQuery calls (I know there are classes out there to do this for me, but is there a simpler way, with arrow/lambda functions?).
Have patience if I'm not grokking the obvious, but it ain't obvious to me!