From cfccdc0084d96fc98cc0aa7773a7b1f1be4d1cb0 Mon Sep 17 00:00:00 2001 From: Bert Hartmann Date: Fri, 10 Oct 2014 23:28:09 -0400 Subject: [PATCH] add some datatype examples --- ex1a-objects.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 ex1a-objects.js diff --git a/ex1a-objects.js b/ex1a-objects.js new file mode 100755 index 0000000..82406d7 --- /dev/null +++ b/ex1a-objects.js @@ -0,0 +1,60 @@ +#! /usr/bin/env nodejs + +var book_list = [ + "Wuthering Heights", + "A Tale of Two Cities", + "Great Expectations", + "Les Misérables" +] +console.log(book_list); +console.log(); + +var victor_hugo = { + name: "Victor Hugo", + born: "18020226", + died: "18850522" +} + +var authors = { + hugo: { + name: "Victor Hugo", + born: new Date("1802-02-26"), + died: new Date("1885-05-22"), + books: [ + "Les Misérables", + "The Hunchback of Notre-Dame" + ] + }, + dickens: { + name: "Charles Dickens", + born: new Date("1812-02-07"), + died: new Date("1870-06-09"), + books: [ + "A Tale of Two Cities", + "Greate Expectations" + ] + } +}; +Object.keys(authors).forEach(function(author) { + console.log(author); + console.log(authors[author].books[0]); + console.log(); +}); + +var Phone = function() { + this.number = parseInt(Math.random()*10000000), + this.carrier = "Verizon" +}; +Phone.prototype = { + call: function(number) { + console.log("Dialing " + number); + console.log("call failed :("); + }, + switchCarrier: function(new_carrier) { + this.carrier = new_carrier; + } +}; + +var my_phone = new Phone(); +console.log("my number: " + my_phone.number); +my_phone.call("855-MakerBar");