ABSTRACT

Making new code use old code is easy: just load the libraries one want and write calls to the functions one need. Making old code use new code without rewriting it is trickier, but object-oriented programming can help. Building every object by hand and calling thing. function is clumsy. JavaScript solved these problems using prototypes, which turned out to be almost as clumsy as our hand-rolled solution. Before new hands the newly-created object back to the program, it calls the specially-named constructor to initialize the object’s state. Inside the constructor and other methods, the object being operated on is referred to by the pronoun this. JavaScript classes support polymorphism: if two or more classes have some methods with the same names that take the same parameters and return the same kinds of values, other code can use objects of those classes interchangeably.