An object is a container for values in the form of properties and functionality in the form of methods.
- Provide functionality through methods. Methods may or may not return values.
- Provides data storage in properties
- The name of the property is a key
- The contents of a property is known as a value
Objects can be categorized into three distinct kinds of objects
- Your Own Objects
To programmatically modify the state of an object or call one of it’s methods from itself we use the keyword this.
Creating Multiple Instances with Constructors
Object literals aren’t the only way to create objects. Object literals are handy when creating one off objects or passing values to a function. Maintaining code with several object literals of the same type can get cumbersome. If you want to create multiple objects of the same kind or type, we need to make use of Constructor functions. A constructor function describes how an object should be created & it will create similar looking objects. Each object created is known as an instance of that object type. An instance is the specific realization of a particular type or object. Constructor functions help in organizing the code by preventing repetition thereby keeping the code DRY.
A Prototype is basically an encapsulation of properties that an object links to. So we can have properties and methods that are on an object’s prototype and for every copy of that object that we have it all links back to the same prototype. It’s much more efficient to have one copy of all of those object methods out there sitting inside the object prototype.
Methods with Prototypes