Last active
August 11, 2016 14:33
-
-
Save dpedro/084af38f23e08a582f95d3e7995e9867 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 classes are introduced in ECMAScript 6 and are syntactical sugar over JavaScript's existing prototype-based inheritance. | |
The class syntax is not introducing a new object-oriented inheritance model to JavaScript. JavaScript classes provide a much simpler and clearer | |
syntax to create objects and deal with inheritance. | |
*/ | |
var Users = class { | |
constructor(fullName, description) { | |
this.fullName = fullName; | |
this.description = description; | |
} | |
} | |
var CONFIG_USERS = { 'users' : { | |
"bob" : { | |
'fullName': 'Bob Dylan', | |
'description': 'Singer-songwriter' | |
}, | |
"john" : { | |
'fullName': 'John Woo', | |
'description': 'Film director' | |
} | |
} | |
} | |
var usersObj = {} = CONFIG_USERS.users; | |
var myUsers = {}; | |
Object.keys(usersObj).forEach(function(key,index) { | |
console.info("key", key); // key: the name of the object key | |
console.info("index", index); // index: the ordinal position of the key within the object | |
let userData = {} = Object.values(usersObj)[index]; | |
console.info("userData", userData); | |
console.info("userData - fullName", userData["fullName"]); | |
myUsers[key] = new Users(userData["fullName"], userData["description"]) ; | |
}); | |
console.info("--»", myUsers); | |
console.info("Bob", myUsers.bob); | |
console.info("Bob - fullName", myUsers.bob.fullName); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment