Front End Engineering June 2015

Wednesday July 22

Questions from Last Night's Reading

  • When would we use prototype? (Shared functionality)
  • if [] are {} then what's the difference (instanceof)
  • prototype vs assignment and regular {} (Constructors)
  • Prototypes and Scope (private variables)
  • Getters and Setters



Suggested Reading

There's been still some confusion about "what is a function", "what does a method mean", "what does property mean". So, if you ask any of those questions and can't answer quickly, then read:

Extra Reading

Once again, try reading the Eloquent Javascript chapters from the last two days:


Tonight you will be working on the prototype exercise:

Getting Started on HW

Setup for tonight's HW

  • Create new folder 4.3-prototypes
  • Initialize git in this new project
  • Copy constructors.js
  • Create .jscsrc and set things up for Airbnb code style
  • Commit to master
  • Create github repo (hub create)
  • Push
  • Switch to develop
  • Succeed!

Gems from the Slackiverse

Since Slack isn't permanent I will try to start copying some of the most helpful questions and answers from the slack rooms:

Better Prompt for Question 4

// Create a constructor called `KeepSecret`. The constructor function
// itself should accept a parameter called `secret` it should keep this
// as a private variable. Add a function to `KeepSecret` that is called
// `squeal` that returns the secret string.

Better Prompt for Question 5

// Create a constructor called `Key`. Create another constructor
// called `Safe`. Make the Safe constructor take 2 arguments. The
// first argument can be any piece if data to keep safe. This must
// be stored using a private variable like you did with KeepSecret.
// The 2nd param to the `Safe` constructor needs to be an instance
// of `Key` you need to store it as a private variable. Then, add a
// function to the Safe prototype called `unlock` that accepts a key. 
// If the key matches the key that was used to create the Safe; then
// return the secret data.

What is a property?

When we talk about a property all we mean is that there is a value on an object.

If I want a property called say on a Dog equal to life if rough, then I should be able to run var d = new Dog() and when I check the value say it should always return life is rough.

What is a method?

When we talk about a method that just means that there is a function available on an object.

So if an assignment says that a Cat should have a method growl, I should be able to create a Cat with var c = new Cat() and then run c.growl().