Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // First we are creating or getting some users and placing them in `users`
- const users = [
- { name: 'Bob' },
- { name: 'Alice' },
- ]
- // Then we are creating a config object that we could pass around as needed
- // Notice we are using shorthand `users` instead of `users: users`
- const config = {
- appOwner: 'Prakash Pawar',
- users,
- }
- // Then we are creating an object that holds functions to quickly access anywhere
- const actions = {
- showUser: user => console.log('User:', user.name),
- addLineThenShowUsers: (users) => {
- console.log('\n=================')
- users.forEach(user => console.log('User:', user.name))
- },
- }
- // Lets investigate what we have now, some Plain Old JavaScript Objects (POJOs)
- console.log('We got users:', users)
- console.log('We got config:', config)
- console.log('We got actions:', actions)
- console.log('\nWho is the 2nd user?', users[1].name)
- // We can always check if something is there or not with a ternary operator
- // It's like an if/else statement but can be thrown around as a Boolean
- // We use names like `isUserLoaded` or `hasBorder` to tell the developer how to read it
- const isAlice = (users[1].name === 'Alice') ? true : false
- console.log('Is it Alice?', isAlice)
- // What if we do something crazy now?
- console.log('\n')
- // Let's call the actions we made
- actions.showUser(users[1])
- actions.addLineThenShowUsers(users)
- // Lets make an app now
- const app = {
- users,
- config,
- actions
- }
- console.log('\nAPP:', app)
- console.log('\nApp Owner:', app.config.appOwner)
- console.log('\n=================')
- app.users.forEach((user, i) => {
- console.log('User:', user.name)
- console.log('Owned by:', app.config.appOwner)
- console.log('--------------')
- })
- console.log('=================')
Add Comment
Please, Sign In to add comment