Question:

Use object literal notation to create an object that has the same behavior as the objects created by the following constructor function.

function Calculator() {
  this.square = function (x) {
    return x * x;
  }
}

Answer:

var my_calculator = {
  square: function (x) {
    return x * x;
  }
}

Constructor functions are just specialized functions that can be used to create the same objects that are created with object literal notation.


Keywords:

© 2017 QuizBucket.org