Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation #5

Open
4 tasks
jugglinmike opened this issue Sep 25, 2014 · 0 comments
Open
4 tasks

Animation #5

jugglinmike opened this issue Sep 25, 2014 · 0 comments

Comments

@jugglinmike
Copy link
Collaborator

Now make the Mole respond in a slightly more interesting way.

  • mole.js
    • Update the Mole's element to be initially invisible
    • Define an instance method on the Mole named show that makes the
      mole appear
    • Update the Mole's "click" event handler to hide the Mole again
  • main.js
    • Call show on the Mole instance after you've inserted its element
      into the DOM

The Mole class now needs a custom function (sometimes called a "method").
Remember: a class is a "template" or "mold" for creating objects. This
means that we can attach the show method to the Mole class, and all the
moles we create will share it.

But I don't want to just give you the solution, so I'll update the "Car" class
from earlier:

function Car() {
  this.wheels = 4;
}

// The `Car` class has a property named "prototype". Anything we attach to that
// object will be defined on the `Car` instances
Car.prototype.beep = function() {
  // Inside an "instance method" like this one, `this` refers to the car
  // instance
  console.log('I am a car! I have ' + this.wheels + ' wheels! Beep beep!');
};
// Later, when we've created a `Car` instance...
var thirdCar = new Car();

// It has a "beep" method that we can call!
thirdCar.beep();
@jugglinmike jugglinmike modified the milestone: The First Mole Sep 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant