Ways to create objects

by Jennifer Piccione

JavaScript

/*
There are three ways to create an object 
*/

/*
(1) object literal:
*/

var x = {
    name: "Foo",
    color: "Red"
}

/*
(2) takes one argument as what it's prototype should be set to
*/

var x = Object.create(Object.prototype);

var a = Object.create(x); //sets a.__proto__ to object x

/*
(3) contructor syntax
*/

var y = new Object(); //essentially calls Object.create(Object.prototype)