Javascript: / Home / TitleClass

The "Title" Class

A Class definition is coded in Javascript by starting with the "class" keyword and then the Class name.

The class definition is contained within the opening and closing braces just like a function.

Methods are what functions should be called when they are inside a Class. However, Methods are defined differently from functions because they do not start with the keyword "function".

  // Code in IntroToJS.js file.
  class LJCTitleClass
  {
    // Adds the required event handler assignment.
    AddEvents()
    {
      //let pageTitle = document.getElementById("pageTitle");
      pageTitle.addEventListener("click", this.TitleClick.bind(this));
    }

    // The title click event handler.
    TitleClick()
    {
      alert("The Title was clicked.");
    }
  }
<- Classes            ClassEvents ->
13TitleClass