Last active
December 22, 2015 18:59
-
-
Save stevencombs/6516651 to your computer and use it in GitHub Desktop.
Javascript Object Formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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