Created
January 20, 2018 20:20
-
-
Save schamblee/c436501f8e36f472b4aa1d87fc4e0a28 to your computer and use it in GitHub Desktop.
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
Object creator | |
function createMyObject(key1, key2, key3, key4) { | |
obj = { | |
foo: 'bar', | |
answerToUniverse: 42, | |
'olly olly': 'oxen free', | |
sayHello: function sayHello() { | |
return `hello` | |
} | |
} | |
return obj | |
} | |
Object updater | |
function updateObject(obj) { | |
obj.foo = 'foo'; | |
obj.bar = 'bar'; | |
obj.bizz = 'bizz'; | |
obj.bang = 'bang'; | |
return obj | |
} | |
Self-reference | |
function personMaker() { | |
var person = { | |
firstName: 'Paul', | |
lastName: 'Jones', | |
// replace `null` with a function that uses self reference to return | |
// full name | |
fullName: function() { | |
return `${person.firstName} ${person.lastName}` | |
}, | |
}; | |
return person; | |
} | |
Deleting keys | |
function keyDeleter(obj) { | |
delete obj.foo; | |
delete obj.bar; | |
return obj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment