A class in Javascript

A class in Javascript defines the characteristics of an object. A class contains object properties and object behaviors. A class will become an object, when it is defined and instantiated. In order to access it’s properties, state and behavior, we have to instantiate a class in our programs.

Eg:

var person = { };

Properties

Properties are the characteristics of an object: A person object will have its own characteristics and the Dog, Monkey and Duck objects as well, they have their own properties and values, such as name, kind and type.

Eg

var person = { name:”Dann”, color:”Green”, planet:”unknown” };

Methods or Functions

Object behaviors are showen in functions/methodes. A person methode could have the walk, talk and eat functions or methods.

Eg:

var person = { name:”Dann”, color:”Green”, planet:”unknown”, details : function(){return this.name + this.color + this.planet; } };

Object

Object is, an instance of a class. Instantiating a class is like asking a person to give you his ID-card and once you have it, you could access its details.

Eg

person.details();