r/javascript • • Feb 21 '18

I am A JavaScript instructor at Microsoft. AMA.

Hi r/javascript!

My name is Benjamin Lin. I am a content developer at Microsoft and teach courses on JavaScript and JavaScript frameworks at Microsoft. You can see my Top 10 JavaScript Questions course here.

I can help answer tips & tricks on learning JavaScript, questions about Microsoft, and all things tech.

AMA!

Proof.

Edit: about 15 minutes left!

More edit: Thanks everyone for visiting me at this AMA! I really enjoyed getting the chance to interact with the JavaScript community and hear your honest thoughts. It was worth waking up early today to do this =)

if you have any more questions, feel free to hit me up on twitter @benjlin or follow me on instagram @bens_jams

540 Upvotes

257 comments sorted by

View all comments

Show parent comments

31

u/MicrosoftLearning Feb 21 '18

Whatever 'this' refers to depends on the context in which 'this' was called.

For the most part, I only deal with 'this' when binding functions to React components.

Here is a good resource on 'this'

6

u/Yoyoge Feb 21 '18

How about a good resource on async? It is driving me nuts as I'm coming from decades of top to bottom thinking.

25

u/MicrosoftLearning Feb 21 '18

I wrote a course on async programming that covers callbacks, Promises and network requests.

Link: Asynchronous Programming with JavaScript

3

u/Yoyoge Feb 21 '18

Thanks

1

u/mikekreuzer Feb 25 '18

Late to the party, but keep in mind globals work differently in node too, so eg

In the browser

function foo() {
  console.log( this.a );
}
var a = 2;
foo(); // a

In nodeland

function foo() {
  console.log( this.a );
}
global.a = 2; // node globals
foo(); // a

-1

u/Ob101010 Feb 21 '18

Yeah, I finally got 'this' down, but it was the last of the hard things.

Quick, explain 'this' using an analogy that a 5 year old would understand.

'this' is the only concept that I found difficult to do that to.

17

u/MicrosoftLearning Feb 21 '18

hmm ill try:

this is used to find the home where you belong

9

u/ForScale Feb 21 '18

ELI5: this is the "house" you are in when you say it.

Say this outside standing on the globe, and this is the globe. Say this in your apartment, and this is your apartment. Or you can get sneaky and take a pic (some might call this "binding") of your apartment with you to another apartment and look at your apartment within the other apartment when you say this, and then this is still your apartment... or whatever you took a picture of.