Slide 1

Slide 1 text

what we talk about @vaidehijoshi when we talk about the javascript object model

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

(we’re hiring!)

Slide 5

Slide 5 text

{}

Slide 6

Slide 6 text

let cat = {};

Slide 7

Slide 7 text

let cat = { sound: “meow” };

Slide 8

Slide 8 text

cat.sound

Slide 9

Slide 9 text

cat.sound cat[“sound”]

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

property descriptors

Slide 12

Slide 12 text

meta objects for all the properties on an object

Slide 13

Slide 13 text

meta objects for all the properties on an object

Slide 14

Slide 14 text

cat.sound

Slide 15

Slide 15 text

Object.getOwnPropertyDescriptor( cat, “sound” ); cat.sound

Slide 16

Slide 16 text

Object.getOwnPropertyDescriptor( cat, “sound” ); { value: "meow", writable: true, enumerable: true, configurable: true } cat.sound

Slide 17

Slide 17 text

{ value: "meow", writable: true, enumerable: true, configurable: true } cat.sound

Slide 18

Slide 18 text

{ value: "meow", writable: true, enumerable: true, configurable: true } cat.sound

Slide 19

Slide 19 text

value writable cat.sound

Slide 20

Slide 20 text

value writable cat.sound data property

Slide 21

Slide 21 text

data property

Slide 22

Slide 22 text

data property has a value, which might be editable

Slide 23

Slide 23 text

data property

Slide 24

Slide 24 text

data property object string number

Slide 25

Slide 25 text

let cat = { sayHi: function() { return “Hi!”; } };

Slide 26

Slide 26 text

let cat = { sayHi: function() { return “Hi!”; } }; cat.sayHi = function() { return “No, I will not say hi. I am a cat.”; };

Slide 27

Slide 27 text

Object.getOwnPropertyDescriptor( cat, “sayHi” ); { value: ƒ(), writable: true, enumerable: true, configurable: true }

Slide 28

Slide 28 text

cat.sound

Slide 29

Slide 29 text

{ value: "meow", writable: true, enumerable: true, configurable: true } cat.sound

Slide 30

Slide 30 text

enumerable configurable

Slide 31

Slide 31 text

enumerable configurable

Slide 32

Slide 32 text

enumerable configurable for…in

Slide 33

Slide 33 text

enumerable configurable for…in Object.keys()

Slide 34

Slide 34 text

enumerable configurable

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

getters & setters

Slide 37

Slide 37 text

let cat = { sound: “meow”, };

Slide 38

Slide 38 text

let cat = { sound: “meow”, }; get loudSound() { return this.sound.toUppercase() + Math.random(); }

Slide 39

Slide 39 text

let cat = { sound: “meow”, }; get loudSound() { return this.sound.toUppercase() + Math.random(); }

Slide 40

Slide 40 text

Object.getOwnPropertyDescriptor( cat, “loudSound” );

Slide 41

Slide 41 text

Object.getOwnPropertyDescriptor( cat, “loudSound” ); { get: ƒ(), set: undefined, enumerable: true, configurable: true }

Slide 42

Slide 42 text

get set cat.loudSound

Slide 43

Slide 43 text

get set accessor property cat.loudSound

Slide 44

Slide 44 text

accessor property

Slide 45

Slide 45 text

has a pair of getter + setter functions accessor property

Slide 46

Slide 46 text

accessor property

Slide 47

Slide 47 text

set ƒ() accessor property

Slide 48

Slide 48 text

set ƒ() get ƒ() accessor property

Slide 49

Slide 49 text

get loudSound() { return this.sound.toUppercase() + Math.random(); }

Slide 50

Slide 50 text

cat.loudSound() > "MEOW0.2812205663401923" get loudSound() { return this.sound.toUppercase() + Math.random(); }

Slide 51

Slide 51 text

cat.loudSound() > "MEOW0.2812205663401923" get loudSound() { return this.sound.toUppercase() + Math.random(); } cat.loudSound() > "MEOW0.41972556946839834"

Slide 52

Slide 52 text

cat.loudSound() > "MEOW0.2812205663401923" get loudSound() { return this.sound.toUppercase() + Math.random(); } cat.loudSound() > "MEOW0.41972556946839834" cat.loudSound() > “MEOW0.5109470702014649"

Slide 53

Slide 53 text

cat.loudSound > "MEOW0.2812205663401923" cat.loudSound > "MEOW0.41972556946839834" cat.loudSound > “MEOW0.5109470702014649"

Slide 54

Slide 54 text

data property accessor property

Slide 55

Slide 55 text

extensible

Slide 56

Slide 56 text

new properties can be added to the object extensible

Slide 57

Slide 57 text

enumerable configurable

Slide 58

Slide 58 text

no removing or adding of properties, but continue to write

Slide 59

Slide 59 text

no removing or adding of properties, but continue to write Object.seal()

Slide 60

Slide 60 text

let cat = { sound: “meow” };

Slide 61

Slide 61 text

let cat = { sound: “meow” }; Object.seal(cat);

Slide 62

Slide 62 text

let cat = { sound: “meow” }; Object.seal(cat); { configurable: false, enumerable: true, value: “meow”, writable: true }

Slide 63

Slide 63 text

no removing or adding of properties and no writing to properties, either!

Slide 64

Slide 64 text

no removing or adding of properties and no writing to properties, either! Object.freeze()

Slide 65

Slide 65 text

let cat = { sound: “meow” };

Slide 66

Slide 66 text

let cat = { sound: “meow” }; Object.freeze(cat);

Slide 67

Slide 67 text

let cat = { sound: “meow” }; Object.freeze(cat); { configurable: false, enumerable: true, value: “meow”, writable: false }

Slide 68

Slide 68 text

Object.freeze(cat);

Slide 69

Slide 69 text

Object.freeze(cat); A getter’s value isn’t going to be frozen

Slide 70

Slide 70 text

Object.freeze(cat); A getter’s value isn’t going to be frozen Properties that have other objects as their value need to be frozen

Slide 71

Slide 71 text

enumerable

Slide 72

Slide 72 text

only an object’s own properties are enumerable*

Slide 73

Slide 73 text

only an object’s own properties are enumerable* *its parent’s (prototype) properties will not be enumerable

Slide 74

Slide 74 text

Object. getOwnPropertyDescriptors([]) { length: { value: 0, writable: true, enumerable: false, configurable: false }, __proto__: Object }

Slide 75

Slide 75 text

Object. getOwnPropertyDescriptors([]) { length: { value: 0, writable: true, enumerable: false, configurable: false }, __proto__: Object } we don’t want these to show up in a loop!

Slide 76

Slide 76 text

objects are complex!

Slide 77

Slide 77 text

objects are complex! but also super cool

Slide 78

Slide 78 text

objects are complex! but also super cool don’t be afraid to peek under the hood at how they work!

Slide 79

Slide 79 text

@vaidehijoshi thank you!

Slide 80

Slide 80 text

@vaidehijoshi thank you!

Slide 81

Slide 81 text

@vaidehijoshi thank you! basecs.org

Slide 82

Slide 82 text

baseds.org @vaidehijoshi thank you! basecs.org