Need help, i'm stuck in this part

When I came to this part, I encountered two new concepts: ''new'' and ''this''. I tried to read and study them, but I still don't understand how to use them and how they work. Can someone help me explain in the most understandable way? thank you.

I think this video from @funfunfunction is pretty helpful, you should listen to it!

2 Likes

The new keyword is used in javascript to create a object from a constructor function.

In JavaScript , ‘this’ normally refers to the object which ‘owns’ the method.

Example you can hide a button on it’s click even with JavaScript this like this:

<button onclick="this.style.display='none'">
  Click to Remove Me!
</button>
1 Like

Oh! I got it, thanks

1 Like

I’d like to point one thing here. Don’t confuse regular functions with arrow functions. They kinda do the same thing, but behave differently when it comes to binding ‘this’ context.

Here is what I mean in this example - https://codepen.io/anon/pen/ZwZLLO

1 Like

this is a really tricky subject in javascript, it refers to different things depending on where in the code you use it and if you are in strict mode or not.

https://www.udacity.com/course/object-oriented-javascript--ud711 this is a good course according to me.