Skip to content

Challenge Make Instances of Objects with a Constructor Function

SaintPeter edited this page · 1 revision
Clone this wiki locally

A function that creates objects is called a constructor, my favorite way of creating objects when you have to create more than one of the same object. You can also edit the second object to add more properties if needed. This is called creating instances of an object.

Each new instance of this object inherits all the properties and methods of your original object.

var Car = function() {
   this.wheels = 4;
};

// New instance of Car object.
var myCar = new Car();

//Add the property "engines" to myCar, and make it a number.
myCar.engines = 1;
Something went wrong with that request. Please try again.