Object Oriented JS

On JS Objects

JavaScript Objects are basically blueprints that you can call and reference at a later time. We typically create and set JS objects in the model.js file of our JS folder in our application. Three main ways to make/call JS Objects.

Object Literal = {}

Object literals are just hashes of key, value pairs. You can set the values to functions and use the functional scope within those values, but other than these special cases you do not have functional scope within object literals. This means you cannot use the keyword 'this'in object literals because they are NOT FUNCTIONS! Example of object literals:

var age = {

randomFunction : function(){}

attribute : 5

}

Call by age.randomFunction();

or age.attribute;

var Object Constructors = function(){};

Constructors and prototypes are functions, but ony Constructors use the keyword 'this'

Example of object constructors:

Object.prototypes

Object prototypes are functions as well. We typically use prototypes within constructors and they act as our 'class' methods since prototypes are created only once and not with each instance of an object(as the case with constructors). They look like this: