1. An Objective Review


#1

var james = {
// add properties to this object!
james.job ="programmer";
james.married = false ;

};

function Person(job, married) {
this.job = job;
this.married = married;
}

// create a "gabby" object using the Person constructor!
var gabby = new Person("student", true);

Oops, try again. There was a problem with your syntax.


#2

These two should be universal constructors using the this. keyword,

to,

this.job ="programmer";
this.married = false ;

#4

Should be:

var james = {
   // add properties to this object!
   job: "programmer", // you don't need this, = , and ;
   married: false
}; // literal notation

function Person(job, married) {
   this.job = job;
   this.married = married;
}; // constructor 

// create a "gabby" object using the Person constructor!
var gabby = new Person("student", true);

UPDATED.
When you are using literal notation you don't need keyword this because only james has properties job, married. And if you want create another object (using literal notation) you also need add properties job, married.
Constructor function Person(job, married) is better when you don't how many objects you need to create. In this case we use keyword this. Example:

var gabby = new Person("student", true);
var tom = new Person("student", false);

It's mean that this has gabby object in the 1st case, and tom object in the 2nd.

I hope this example help you to understand what I want to say.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.