Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What we talk about when we talk about the javas...

What we talk about when we talk about the javascript object model (donutJS)

If you've ever used JavaScript, you've probably created an object at some point. JavaScript's object model is used by many, but perhaps understood by few. In this talk, we'll explore the inner workings & hidden properties of JS objects, as well as how to interact with them, and why they even matter.

Vaidehi Joshi

February 26, 2019
Tweet

More Decks by Vaidehi Joshi

Other Decks in Technology

Transcript

  1. {}

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

    }; cat.sayHi = function() { return “No, I will not say hi. I am a cat.”; };
  3. let cat = { sound: “meow”, }; get loudSound() {

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

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

    } cat.loudSound() > "MEOW0.41972556946839834" cat.loudSound() > “MEOW0.5109470702014649"
  6. let cat = { sound: “meow” }; Object.seal(cat); { configurable:

    false, enumerable: true, value: “meow”, writable: true }
  7. no removing or adding of properties and no writing to

    properties, either! Object.freeze()
  8. let cat = { sound: “meow” }; Object.freeze(cat); { configurable:

    false, enumerable: true, value: “meow”, writable: false }
  9. 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
  10. Object. getOwnPropertyDescriptors([]) { length: { value: 0, writable: true, enumerable:

    false, configurable: false }, __proto__: Object } we don’t want these to show up in a loop!
  11. objects are complex! but also super cool don’t be afraid

    to peek under the hood at how they work!