Section 1: Defined
JavaScript Objects
In JavaScript, an object is an unordered collection of key-value pairs.
- Each key-value pair is called a property.
The key of a property can be a string and the value of a property can be any valid JavaScript value e.g., a string, a number, an array, and even a function.
- When a function is a property of of an object, it’s often called a method.
Objects are dynamic bundles of data.
- Everything in JavaScript is an object, with the exception of primitive types.
-
Objects use { }
-
Remember, arrays use [ ] (square brackets)
- Here is a nice Introduction to JavaScript objects.
JavaScript has no Classes
- Just instances of objects
-
No real class keywords
-
Class keyword does exist, but...
- Just to make programmers feel warm fuzzies
- JavaScript classes are often referred to as "syntactical sugar" because they offer a cleaner way to do object-oriented programming in JavaScript.
-
Class keyword does exist, but...
Section 2: Declaration
As an object literal
Using the "new" keyword
As a generic object
Section 3: Attributes
Attributes of JS objects
Objects are a HashMap 
- Key-value; pairs of data
Attributes are called properties
- Can be added at the start:
- Or added later:
Section 4: Object Methods
Properties can be functions
Properties can be set to named functions
Literal - Can create by just assigning an anonymous function to properties.
Functional - Can be set in functional created objects by setting the field to an anonymous function.
Functional Named - Can be set in functional created objects by setting the field to a named function within the object.
Section 5: This
This is a reserved keyword.
- Refers to the owning object.
What is "this"?
What is "this"?
Section 6: Constructors
Use a functional construction to use constructors.
Constructors are just functions
Section 7: Functional Objects
Functions are objects
Functions have a prototype of Function:Prototype
Example
Functional Objects & Instantiation
Section 8: Prototype Chains
When it comes to inheritance, JavaScript only has one construct: objects.
- Each object has a private property that holds a link to another object called its prototype.
- That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype.
- By definition, null has no prototype, and acts as the final link in this prototype chain.
The above was taken from Inheritance and the prototype chain.
When you create an object, that object automatically gets a prototype.
- If your new object references a property or method that is not in the object itself, JavaScript will look in the prototype to see if it was declared as part of the prototype.
There is an excellent video explanation in JavaScript Classes vs Prototypes
Here are some additional references that are useful:
- Prototypal inheritance
- JavaScript Object Prototypes
- JavaScript Prototypal Inheritance
- Video: Javascript Prototype inheritance Explained (tutorial Part 1)
- Video: Javascript Prototype inheritance explained ( tutorial part-2)
- Video: Prototype basics - Object Creation in JavaScript P3 - FunFunFunction #46
- Video: JavaScript Question: What is a Prototype?
Creating Prototype Chains
The Object.create function can be used to create an Object with any other Object as it's prototype.
More on Setting an Object's prototype.
Own Properties
A JavaScript object can have either own or inherited properties.
- The own property means that the property is defined directly on the object.
- On the other side, the inherited property is the one inherited from the prototype object.
More details can be found in Understanding Own Properties of an Object in JavaScript
Property shadowing
When creating a property on an object that has the same property name on its prototype chain it will shadow
the property on its prototype.
- This means that the property defined on the object will always be found first instead of looking through the prototype for the property.
- You can find more details at JavaScript Objects: Property Shadowing
Prototype Chain (Watch Window)
Prototype Chain
Prototype Chain
Section 9: Arrays or Objects?
Arrays are objects (not an instance of "Object")




