- What's New?
- Modifying the Prototype
- State and Behavior
- JavaScript COLA
- Objective-C in Smalltalk
JavaScript COLA
The JavaScript model is very similar to the Combined Object Lambda Architecture (COLA) design. This simple self-hosting system is from the Viewpoints Research Institute (VPRI). The COLA model was intended to be the simplest possible object-oriented programming language that was expressive enough to implement itself.
From an experimental standpoint, the COLA model is quite interesting, but it also provides a useful model for understanding object-oriented languages at a theoretical level. The COLA model has two primitive types: objects and closures. An object receives messages and handles them by calling a closure or forwarding the messages to another object. As with JavaScript, COLAs support prototype delegation; however, unlike in JavaScript, each object can decide how this delegation works. It may have a single prototype, or a series of prototypes with different priorities for various message types.
This model helps if you want to think of object-oriented languages in terms of lambda calculus. Fundamentally, there's no difference between an object and a closure. In Simula, a class was just a closure that returned itself. Local variables in a closure and fields in an object are equivalent. This is especially easy for JavaScript programmers to understand, because local variables in a JavaScript closure can be accessed as fields on the this object.
Thinking from the other direction, a closure is just an object with a single method. In Smalltalk, closures are instances of the BlockClosure class, and implement #value, #value:, #value:value:, and so on, methods depending on their number of arguments.
When you realize this relationship, you see that it's quite trivial to build other object models in JavaScript. Any language that provides closures can implement complex object models, and a language that provides dictionaries can usually implement them very easily.