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
Alcibiades Montas
5,974 PointsJavascript object question
I have the following piece of code:
//this is an object constructor function Person(name,age) { this.name = name; this.age = age; }
// This function prints the name of any given person var printPersonName = function (p) { console.log(p.name); };
//declaring a person var bob = new Person("Bob Smith", 30); //calling the function printPersonName(bob);
My question is simple.....how does my function knows to refer to my object only by providing .name and P? I am not declaring the whole name and yet is returning Bob.
1 Answer
Alcibiades Montas
5,974 PointsActually never MIND!!! I see that I am passing the name when I call the function!