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 trialMuhammad Rizwan
8,595 PointsHi, I am sorry I do not understand why this.name is bond to riz and why name which is in function bond to parameters?
var riz ={
name: "Rizwan",
skills:["HTML", "CSS", "JavaScript"],
greet: function (name, mood){
name = name || "you";
mood = mood || "good";
console.log("Hello, "
+ name +
" I am "
+ this.name +
" and I am in "
+ mood + " mood.");
}
};
2 Answers
Hugo Paz
15,622 PointsHi Muhammad,
'riz' is a javascript object. name, skills and greet are all properties of that object. When you want to call a property you do it like this:
riz.name
If you type this on your browsers console, you get 'Rizwan'.
Greet is another property which in this case is a function with 2 parameters, name and mood. The name in the function is not the same name in the object. Using an example makes it clearer. Typing this on the console:
riz.greet('Hugo', 'great')
you will get this:
Hello, Hugo I am Rizwan and I am in great mood.
The name you passed in the function appears first and then the name stored in the object (this.name) appears after.
Brian Gallagher
9,074 PointsGreat explanation. Really helpful. Thanks Hugo!