Last active
August 29, 2015 14:08
-
-
Save brandonvanha/1ffd035a95e45b4542a0 to your computer and use it in GitHub Desktop.
Cheat Sheet: Working with Objects
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
Cheat Sheet: Working with Objects | |
This section is a quick reference with pointers to more thorough explanations. | |
• Object literals (see “Object Literals” on page 198): | |
var jane = { | |
name: 'Jane', | |
'not an identifier': 123, | |
describe: function () { // method | |
return 'Person named '+this.name; | |
}, | |
}; | |
// Call a method: | |
console.log(jane.describe()); // Person named Jane | |
• Dot operator (.) (see “Dot Operator (.): Accessing Properties via Fixed Keys” on | |
page 199): | |
obj.propKey | |
obj.propKey = value | |
delete obj.propKey | |
• Bracket operator ([]) (see “Bracket Operator ([]): Accessing Properties via Computed | |
Keys” on page 202): | |
obj['propKey'] | |
obj['propKey'] = value | |
delete obj['propKey'] | |
• Getting and setting the prototype (see “Getting and Setting the Prototype” on page | |
214): | |
Object.create(proto, propDescObj?) | |
Object.getPrototypeOf(obj) | |
• Iteration and detection of properties (see “Iteration and Detection of Properties” | |
on page 217): | |
Object.keys(obj) | |
Object.getOwnPropertyNames(obj) | |
Object.prototype.hasOwnProperty.call(obj, propKey) | |
propKey in obj | |
• Getting and defining properties via descriptors (see “Getting and Defining Properties | |
via Descriptors” on page 224): | |
Object.defineProperty(obj, propKey, propDesc) | |
Object.defineProperties(obj, propDescObj) | |
Object.getOwnPropertyDescriptor(obj, propKey) | |
Object.create(proto, propDescObj?) | |
• Protecting objects (see “Protecting Objects” on page 229): | |
Object.preventExtensions(obj) | |
Object.isExtensible(obj) | |
Object.seal(obj) | |
Object.isSealed(obj) | |
Object.freeze(obj) | |
Object.isFrozen(obj) | |
• Methods of all objects (see “Methods of All Objects” on page 257): | |
Object.prototype.toString() | |
Object.prototype.valueOf() | |
Object.prototype.toLocaleString() | |
Object.prototype.isPrototypeOf(obj) | |
Object.prototype.hasOwnProperty(key) | |
Object.prototype.propertyIsEnumerable(propKey) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment