Skip to content

Challenge Make Instances Of Objects With A Constructor Function

Quincy Larson edited this page Aug 20, 2016 · 1 revision

Challenge Make Instance of Objects with a Constructor Function

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;
Clone this wiki locally