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 Object-Oriented JavaScript (2015) Introduction to Methods Understanding this

alex gwartney
alex gwartney
8,849 Points

Not sure of the question of what its wanting me to do with the key word this?

So i under stand what the key word this is but im not sure what the question is wanting me to do because its not all that clear to me could some one explain it thanks?

object.js
var contact = {
  fullName: function() {
      firstName:"Andrew";
    lastName:"Chalkley";
    console.log(firstName + " " + lastName);
  }
}

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Alex;

The idea is to take the variables out of the function and declare them elsewhere and to start converting things into objects. As an example, and not to try to give too much away...

var address = {
    streetAddress: function() {
        var houseNumber = "123";
        var streetName = "Elm Street";
        console.log(houseNumber + " " + streetName);
    }
}

In object-oriented JavaScript you would like to have that cleaned up as:

var address = {
    houseNumber: "123",
    streetName: "Elm Street",
    streetAddress: function() { 
         console.log(houseNumber + " " + streetAddress);
    }
}

Now our address looks a lot like a JSON object, right? Step 2 in the challenge will bring the use of the keyword this into play.

Happy coding,

Ken

alex gwartney
alex gwartney
8,849 Points

hmm weird ok i tried that last night must have typed things in correctly but thanks for the better explanation of the question makes much more sense now.

alex gwartney
alex gwartney
8,849 Points

ok so i figured out why it wasnt working to begin with i for got to add a , to the second object above the function