1-6 Javascript Objects

An object is a collection of related data and/or functionality. This usually consists of several variables and functions, called properties and methods when they are inside objects.

Properties are the values associated with an object. They can usually be modified, added, and deleted.

Methods are the actions that can be performed on objects. They are properties containing a function definition.

Car Object Example

This would all work the same in a video game. In a video game, you might have a character object. You can create as many versions of that character object as you need.

Properties of the character object could be hair style, skin color, clothing, eye color, weapon, special move, etc. Each of those properties would have a value:

character1.clothing = "red_flame_dress"
character1.weapon = "fireball"
character1.eyeColor = "blue"

This could all be combined in code like this:

var character1 = {clothing:"red_flame_dress", weapon:"fireball", eyeColor:"blue"};

The character would also have methods associated with it. The character could do things like walk, run, use their weapon, etc. It would look like this: