Class Methods

Consider a program where we represent a bunch of people who can introduce themselves. We could make a Person class and give it a Method (a function) named greet()

class Person {
  constructor(name) {
    this.name = name;
  }

  greet() {
    console.log("Hello, my name is " + this.name);
  }
}

We can now make some different Person objects and have them greet().

var person1 = new Person("Jason");
var person2 = new Person("Ally");

person1.greet(); //Logs "Hi, my name is Jason"
person2.greet(); //Logs "Hi, my name is Ally"

In our lessons we usually deal with drawing and moving lots of objects. To handle this we usually create a draw() and a move() method, that way we can tell all of our player's to .draw() and .move().

Class Methods courses

One-Lesson Javascript Games

Javascript games that can be created in one lesson

Class Methods lessons

Pokemon Battle (with classes!)

Use classes to make two pokemon objects who will battle

Buttons & Classes

A walkthrough for creating a button class that can be used in any project you choose

Related Links

No links found
About Class Methods

These are the actions a class object are able to perform.

Badge

Class Methods