Skip to content

Instantly share code, notes, and snippets.

@khalidwilliams
Last active September 13, 2019 15:58
Show Gist options
  • Save khalidwilliams/bd92d1809e9928551af9e1b3688bb592 to your computer and use it in GitHub Desktop.
Save khalidwilliams/bd92d1809e9928551af9e1b3688bb592 to your computer and use it in GitHub Desktop.

Prototypes:

Classrooms - totalCapacity()

https://repl.it/@Khalid_Williams/Classrooms-totalCapacity

Clubs - membersBelongingToClubs

https://repl.it/@Khalid_Williams/Clubs-membersBelongingToClubs

Cakes - groceryList

https://repl.it/@Khalid_Williams/Cakes-groceryList

Bosses - bossLoyalty

https://repl.it/@Khalid_Williams/Bosses-bossLoyalty

Classrooms - studentsPerInstructor

https://repl.it/@Khalid_Williams/Classrooms-studentsPerInstructor

Classrooms - modulesPerTeacher

https://repl.it/@Khalid_Williams/Classrooms-modulesPerInstructor

Constellations - starsInConstellatinos

https://repl.it/@Khalid_Williams/Stars-in-Constellations

Scope:

https://repl.it/@Khalid_Williams/Scope-1

Answer Key

EXERCISE I:

  • D - strawberry
  • C - mango
  • B - mango
  • A - apple

EXERCISE II:

  • C - Spot
  • D - Spot
  • E - Biscuit
  • B - Biscuit
  • A - Biscuit

EXERCISE III:

  • D - Robbie
  • B - Mr. Robbie
  • C - Bobo
  • E - McJaeger
  • A - McJaeger

EXERCISE IV:

  • C - Travis
  • D - Travis
  • B - Khalid
  • A - Khalid

EXERCISE V:

  • A - Spot
  • B - Spot
  • C - Biscut
  • D - Biscut
  • E - Biscut

EXERCISE VI:

  • A Rody
  • B RodyToy
  • C Tesla
  • D RodyToyDaniels

Context:

https://repl.it/@jsfun/Context

Answer Key

Exercise I: dog

We do not lose the value of this in our anonymous callback function due to the reassignment of this to _this on Line 6. The original context of this refers to dog since it is invoked as a method on an object.

Exercise II: Global Window Object

Normally, invoking a method on an object will make this refer to the parent object. We lose the value of this due to our method being an arrow function instead of an ES5 declaration. this is set lexically with arrow functions

Exercise III: store

Since we are invoking a function as a method on an object, this refers to that object.

Exercise IV: instance of Hero

Since we are invoking a function with the keyword new, this refers to the new instance created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment