Objects in Javascript - Objekt i Javaskript

Modified on 2014/03/18 15:24 by Jovall — Categorized as: Uncategorized

Everything is an object - Allt är objekt

In Javascript everything is an object; apart from the following basic datatypes: strings, numbers, booleans, null and undefined. Objects can be seen as belonging to specific categories. They are:

Objects - Objekt

An object is a collection of properties. Objects are handled as references, not as values. Each object also contains a set of object attributes:

Creating an object

Objects are created by one of three ways:
  1. object literal - a comma-separated list of propertyname-and-value-pairs separated by colon : var theName = { x:1, "main title":"An awesome title" }
  2. using the new operator - calling a constructor function with new : var theName = new NewObject()
  3. using the create function - calling the create-function using the prototype and properties for the new object : var theName = Object.create({x:1}, {y:2, z:3})