An object can be defined as a computing concept combining data and behavior, and having an identity. In class-based programming, objects are built on class systems, where an object is an instance of a class. Classes can in turn be related by inheritance: a base class provides the fundamental or default behavior of an object, and acts as a template for creating objects, while a derived class can be used to override behaviors of a base class, and can be used as a template for objects whose behaviors refine those of the base class.
An alternative to classes and inheritance is prototypes and delegation,[2] which is used in prototype-based programming, and is more dynamic. Instead of using one class to refine another, delegation allows one object to override the behavior of another. The original object a (analogous to the derived class behaviors) can delegate some of its methods to another object b (analogous to the base class behaviors). If a delegates its foo method to the bar method of b, then any invocation of foo on a will cause b's bar method to execute. However, bar executes in the context of the a object, for example, its self
identifier refers to a rather than to b.
When delegation is used, the question arises: What is the value of self
when evaluating a method on object a, which is delegated to a method on object b? The identity is split: it can refer to a or b. Note that while the two objects are separate and have separate physical identity, self
(whether used explicitly or implicitly) is ambiguous.