JavaScript Class Patterns Revisited: Endgame
- by Liam McLennan
I recently described some of the patterns used to simulate classes (types) in JavaScript. But I missed the best pattern of them all. I described a pattern I called constructor function with a prototype that looks like this: function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype = {
toString: function() {
…