Created
April 30, 2017 17:01
-
-
Save NeuTrix/8464f8130c7e8bc6ab8f2b77787905ef to your computer and use it in GitHub Desktop.
running a mini address book to see how changing extensibility for objects works in js
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
"use strict()"; | |
// make a phoneBook object | |
var phoneBook = {}; | |
// add some people objects | |
phoneBook.bob= {name:"Bob",age:35}; | |
phoneBook.greg= {name:"Greg",age:27}; | |
phoneBook.nancy= {name:"Nancy", age:65}; | |
//iterate over each item in the phoneBook | |
// `item` will be returned as a String so use [] method to acces properties | |
var list = function (){ | |
for(var entry in phoneBook) { | |
var person = phoneBook[entry] //a person in the phoneBook | |
console.log("Name: " + person.name + " Age: "+ person.age ); | |
// console.log(person); | |
} | |
}; | |
list() | |
Object.preventExtensions(phoneBook); | |
phoneBook.julie = {name:"Julie", age:45} | |
console.log("*********************") | |
console.log(Object.isExtensible(phoneBook)); | |
list() | |
// MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment