CSX

JavaScript does allow us to create new objects with access to the same properties and methods (without creating new copies of those properties and methods each time) through something called the prototype chain. The last object in your chain will inherit properties and methods from every previous object in the prototype chain.

Front End Masters

Screen Shot 2022-04-22 at 12.54.54 AM.png

Objects - store functions with their associated data. (Encapsulation)

  1. Dot Notation

    Screen Shot 2022-04-22 at 12.58.29 AM.png

  2. Object.create

    Screen Shot 2022-04-22 at 12.59.43 AM.png

    1. Creating Objects with Functions

    Screen Shot 2022-04-22 at 1.12.02 AM.png

    Screen Shot 2022-04-22 at 1.12.15 AM.png

    ====

    Prototype & New

    Avoid Duplication with Prototype

    Screen Shot 2022-04-22 at 1.18.30 AM.png

    Screen Shot 2022-04-22 at 1.18.45 AM.png

    Screen Shot 2022-04-22 at 1.24.38 AM.png

    Screen Shot 2022-04-22 at 1.24.48 AM.png

    Screen Shot 2022-04-22 at 1.30.25 AM.png

    The new keyword automates three things:

    1. Creates a new user object for us
    2. Return the new user object

    Screen Shot 2022-04-22 at 1.32.13 AM.png

    Functions are both objects and functions.

    Screen Shot 2022-04-22 at 1.32.42 AM.png

    Screen Shot 2022-04-22 at 1.42.42 AM.png

    new Keyword & Share Functions with prototype

    Screen Shot 2022-04-22 at 7.48.17 AM.png

    The class object has key: prototype, which is an object full of methods accessible to all instances of that object.

    The “New” keyword creates an object that inherits all the prototype properties.

    We refer to this specific object as “This”, and we refer to its inherited prototype properties with the key: __ proto __

    this.proto = classObject.prototype

    proto is a hidden bond to the original class Object’s properties

    ===

    The new keyword:

    1. creates an instance of class object: “this”
    2. creates a hidden bond “this.proto” which links to the prototype object of the class object
    3. returns this object

    Review of New

    If you call “this” without “new” in the global context, it refers to the window object.

    Uppercase the first letter of functions that should be run with new () keyword.

    Screen Shot 2022-04-22 at 10.35.20 AM.png