Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Foundations Objects Methods

Too much going on here after "this"

Not a question, just an observation and suggestion.

Sorry, I just got flooded after the "this" function/method/variable. I was fine up until there but when Jim started in on the var jimGreet = jim.greet where we try to take the greet method and store it into a variable and the function whatIsThis()...my head just exploded and I stopped listening.

It's not enough that we have the "this" method to refer to the key "name" in the greet function. Now we're looking at taking the method in the function" (that's already in the "jim" variable/object) and will try to store it into a completely different variable which is "jimGreet". Hence, head exploding.

The more stuff you throw at the JS noobies watching the videos the less likely all of it will stick, even with stopping the videos and slowing them down and taking notes. I'd suggest splitting the video up into two after the "this" function/method/variable.

Devin Gray
Devin Gray
39,261 Points

This is why they created JavaScript Basics which all but replaces JavaScript Foundations, which also confused me royally.

Jennifer Hughes
Jennifer Hughes
11,421 Points

I couldn't agree with you more, Ron.

2 Answers

Stephen Perez
Stephen Perez
4,229 Points

Ron L, as a fellow treehouse-noob i will try an explanation. I know you were not asking a question but working through this explanation may have helped me reason things out. I have not gone through JavaScript Basics yet :x My notation purposefully differs from suggested Markdown notation.

Go back a smidge before the point where your head exploded, start at 9:00, pause at 9:16. When you type jim.greet(); into the browser window this may be being interpreted in these steps:

1) Jump to/locate var jim .
2) within var jim Jump to function greet . 3) Return to console the concatenation of string literal + this.name , so hold up... 4) Associate this.name with this 's container object var jim ; now jim.name = "Jim" = this.name 5) K, now Return to console the concatenation -> Hello I am Jim .

On towards head explosion! Run your video to 9:23. Storing another variable’s property and calling it with (); doesn’t work because this.name now searches for the container.name (step 4 above) only this time, this isn't contained in var jim. In that sense the variable, in our noob-code, is simply not defined. As he menions at 10:30, we have lost the context for the method. I can’t quite put it into words yet but I feel it is similar behaviour as named vs anonymous functions, and their varying impact and relationship with variable scopes.

Now the property .name seems to become associated with the global scope. This part is explained pretty well in the video. An attribute of the JavaScript language is that there is a global object, termed window. It happens that window.name(); has a default value of the string literal ’’ .

From 11:00 the whatIsThis is us going from a "writing program” mentality, stepping into “wtf? debug time” mentality. This is in an attempt to clarify the definition of window.name , for folk like me who assumed it to return as -> undefined simply because it is not literally in our noob-code. End lesson: this is to be used as a method, and not called as part of a function lacking sufficient context that it would Assign to the JS default global object.

If i'm mistaken please correct me so i can learn! these forums are a big reason why Treehouse is pretty wonderful for some peoples' style of learning.

Hey! Just to clear things up for me- are you sure that your step 4 shouldn't be jim.name = "james" = this.name??

Hey Devin,

Yeah...I've already gone through JS Basics. I don't recall any of these being in there.