Object Models
One thing that frequently confuses newcomers to JavaScript is the fact that it doesn't have classes. JavaScript follows the Self model, where method lookup is handled by each object with the capability of delegating to another object, rather than by a class. Self was designed as the logical conclusion of Smalltalk, taking similar syntax but removing everything from the language that could be implemented in a library.
A lot of techniques for optimizing object-oriented languages work with the class-based model. It's trivial to implement classes in a prototype-based language like Self or JavaScript; simply designate some of your objects as classes, and use them only as prototypes. This tactic isn't particularly useful for optimization, however. More helpful would be the ability to go in the opposite direction.
Self is no more expressive than Smalltalk. You can turn a Smalltalk program into a Self program simply by turning all of the classes into prototypes, but can you easily go the other way? It turns out you can, quite trivially. The idea behind the hidden class transform is that you can create a class for every object, which inherits from the object's prototype's class.
By itself, this capability isn't useful at all, but it allows for a lot of other optimizations later on. The first thing you might notice is that you don't actually need to create a class for every single object[md]only for the ones that have methods added to them. This simple observation dramatically cuts down the number of classes you need in a JavaScript program, which helps a lot with some of the other optimizations we'll look at later.
In some cases, you can perform this transform at compile time, by examining functions that are used as constructors. Any objects these functions create can then be implemented as Smalltalk-style objects, where the instance variables that were known at compile time are stored in an array (with references to them just done by computing an offset from the object pointer), and only the instance variables added later are stored in a dictionary. This design can make slot accesses much faster.