Working with Objects
In JavaScript, objects are the primary configurable data structures from which all other complex data types extend, including Array
and Date
. Objects work like a hash map
; they contain key
/value
properties that can contain any data type, including functions and other objects.
An object is defined using curly braces, much like a block:
var myObject = {};
The values that are added to an object are "members" of that object. Those members are accessible using dot notation:
var myObject = {foo: "bar"}; console.log(myObject.foo); // => "bar"
The key of a property may be specified with or without quotes. However, the result is exactly the same:
var myObject = {param1: 1, "param2": 2};
JavaScript is known as a prototype language, which means its object-oriented capabilities are provided by prototyping values to objects prior to instantiation. As such, JavaScript objects support the prototype
keyword...