Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callback functions in TypeScript

I'm just getting started with Angular 2 and TypeScript and I can't seem to figure out how to use callback functions, I know this may be a silly question but given this regular javascript code:

someOnject.doSomething('dsadsaks', function(data){
      console.log(data);
});

What is the equivalent in TypeScript?

like image 487
Leonardo Jines Avatar asked Dec 24 '22 09:12

Leonardo Jines


1 Answers

The same code works in TypeScript. Alternatively you can use

someOnject.doSomething('dsadsaks', data => {
  console.log(data);
});

The difference is that in the 2nd version this. would refer to the class surrounding the code.

like image 56
Günter Zöchbauer Avatar answered Dec 28 '22 11:12

Günter Zöchbauer