Skip to main content

How to use THIS keyword inside a typescript callback method



When using callbacks in Typescript you  would (most of the time) want to invoke object reference methods instead of static methods.

To do this you would need to make use of the "this" keyword inside the callback, but you need to define the callback in a certain way otherwise "this" refers to the callback itself.

The correct way to define the callback method is:

If you are expecting a JSON result in the callback you can define the callback to use parameters like this:

Comments

Popular posts from this blog

Using self-signed certificates with QZ Tray

QZ Tray is an amazing printing tool for your browser. It allows your websites to print receipts including bar-codes using thermal printers. The only problem is that getting it all set up correctly can be a bit tricky especially if you want to suppress the untrusted dialogs/prompts that pop up when using the free version. Lucky for us, their solution is open source and from version 2.02 they allow developers to recompile the source with a self signed certificate that would suppress these popups. This is great if you cannot afford the $400 annual price tag, but getting it set up could be a painful process because they don't offer step by step instructions, and other articles on the subject are incomplete. I successfully managed to recompile the binaries using a self signed certificate and thought it might be useful if I provide step by step instructions on how to get it done. This guide will explain how to recompile the windows binaries only. But this should give you enou

Ethereum, the new BitCoin but better!

If you are like me you probably want to kick yourself for not getting on the BitCoin train back in the day when it was just taking off. Bitcoin has been making some good gains the last few months but there is a newer "Crypto Currency" making all the headlines these days... And this one is still affordable but growing at an incredible rate. This new blockchain is called Ethereum. Important: The purpose behind this article is not to try and convince you to buy or mine Ether, the idea is to bring it to your attention so that you don't sit there 5 years down the line thinking how much different your life could have been if you just invested a few dollars.  Its up to you to do more research to find out if this is something you are interested in or not. I personally would have loved to come across an article like this when BitCoin just took off.  At its simplest, Ethereum is an open software platform based on blockchain technology that enables develo

How to update NuGet Package Manager (NPM) in Visual Studio

How to update your NuGet package manager in Visual Studio. Follow these steps to update NPM in Visual Studio: Click Tools -> Extensions And Updates Select " Updates"  on the left, and then "Visual Studio Gallery" Select NuGet Package Manager  and click Update Accept the agreement NuGet Package Manager is now successfully updated