Programming with Objects

In this lesson, we will formally start programming with objects. Let's begin!

Objects are fundamental concepts in JavaScript. You can create and setup objects in several ways, as this code snippet illustrates:

// "Manual" setup
var car = new Object();
car.manufacturer = "Honda";
car.type = "FR-V";
// Setup with constructor function
var Car = function (manuf, type) {
this.manufacturer = manuf;
this.type = type;
}
var car1 = new Car("Honda", "FR-V");
// Setup with JSON
var car2 = {
manufacturer: "Honda",
type: "FR-V"
};

Each mode of setup results the same object semantically, a car that has a manufacturer and a type ...