Question:

Call the square() method on the my_calculator object.

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

Answer:

console.log(my_calculator.square(5));

Constructor functions can create objects with methods. All objects created by the Calculator constructor in this example have a square() method.


Keywords:

© 2017 QuizBucket.org