Why doesn't 'this.person' work in lesson 3?




I actually managed to get the code for this lesson working correctly in the end, however was curious why my first attempt (using this.firstName etc as opposed to person.firstName) prints 'undefined' 6 times.

In my mind applying logic from the previous chapter seemed to suggest it would work, but clearly this is not the case! Just curious as to why.

Many thanks.

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"

var contacts = [bob, mary];

// printPerson added here
var printPerson = function (person) {
    console.log(this.firstName + " " + this.lastName);




Arguments are referred to by name.

Constructors and methods get a reference to the object that they are creating or are called on:

var Ball = function(color) {
  this.color = color;

Ball.prototype.turnRed = function() {
  this.color = 'Red';

var myBall = new Ball('Blue');
console.log(myBall.color);  // Blue
console.log(myBall.color);  // Red