- Until ECMA6, JavaScript had no classes. It had (and still has) prototypes.
- A class is like a mold from which you build an object. A prototype is itself an object.
// think of this as the class AND its constructor
var Person = function() {
this.canTalk = true;
};
// this is a 'class method'
Person.prototype.greet = function() {
if (this.canTalk) {
console.log('Hi, I am ' + this.name);
}
};
// instantiating
var person = new Person();
Further reading