Question:

Use object literal notation to create an object that behaves similarly to the wilson object that is created with the following Person() constructor:

function Person(first_name, last_name) {
  this.first_name = first_name;
  this.last_name = last_name;
  this.full_name = function () { return this.first_name + " " + this.last_name };
}

wilson = new Person("wilson", "rawls");

Answer:

var wilson = {
  first_name: "wilson",
  last_name: "rawls",
  full_name: function () { return this.first_name + " " + this.last_name }
}

Notice that it would be much easier to make 100 person objects using constructor functions compared to object literal notation. Object literal notation is great if only one object of a specific type is being made, but constructor functions are superior if many objects of a given types will be made.


Keywords:

© 2017 QuizBucket.org