Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Last active December 22, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencombs/6516651 to your computer and use it in GitHub Desktop.
Save stevencombs/6516651 to your computer and use it in GitHub Desktop.
Javascript Object Formatting
// Javascript Object Formatting Syntax
// Both code examples create the same object
// Dr. Steven B. Combs, coding novice
// Object Literal Notation
var me = {
name: 'Steven',
age: '48',
interests: ["coding", "running", "blogging"], // array
};
// Object Constructor Notation
var me = new Object();
me.name = "Steven";
me.age = 48;
me.interests = ["coding", "running", "blogging"]; // array
// Custom Object Contructor Notation using 'this'
function Person(name,age) { // Custom constructor template
this.name = name;
this.age = age;
};
var bob = new Person("Bob Smith", 30);
var susan = new Person("Susan Jordan", 25);
var george = new Person("George Washington", 275);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment