about


Scribe:

chrono

blog

Time

science!

book musings

gov

'punk

missle defense

jams

antiques

cultcha blog


Construct:

scripts & programs

on the town

snaps


Self:

creds (PDF)

key

missive


JavaScript Classes

A class is a type, or category, of objects. Technically speaking, Javascript doesn't recognize the idea of "classes", but they can be emulated.

You define a class using an object constructor.

function Song(name, year, timesPlayed) {
  this.name = name;
  this.yearRecorded = year;
  this.timesPlayed = timesPlayed;
}
You then create objects of this class, using the constructor...
var WildThing = new Song("Wild Thing", 1966, 30);
var MaggotBrain = new Song("Maggot Brain", 1972, 35);
Characteristics of objects can then be brought up by evoking a method...
Song.prototype.announce = function(){
    alert("The next song to be played is" + this.name);
}
A prototype extends a class with additional functionality that is available for all objects of that class.

Example here of how a "class" works in JavaScript...

Back to the JavaScript Page
.