Tag Archives: create new JavaScript object

Creating JavaScript Objects with a constructor function

JavaScript objects can be created using a constructor function.

A constructor function uses the same syntax as a regular function, just the code placed between parentheses is different.
The way you access its content is also different that a regular function.

In the following example I am going to create a function named MyMotorbike and add properties within it.

Naming objects follow the same rules as naming functions and variables.

function MyMotorbike (model, engine, color) {
	this.model = model;
	this.engine = engine;
	this.color = color;

Continue reading