PrototypeJungle images/logo_alt.html
Kits Tutorial Draw Code Editor Text Editor Coding Guide About

The basic operations on prototype structures, supported in the API and in the user interface.

Below is a simple and typical prototype structure, with instances I1,I2, I3 of prototype P1, which is itself an instance of prototype P2. In this case the objects are are one-level, but they might have been trees, as detailed here. See this programming-free explanation of the prototype idea.


The operations:

1. Instantiate. After item.set('I4',P1.instantiate()):

I4 is "bare": it has no own properties.

2. After I1.copy(). In copies, the own properties of the source are replicated in the result of the copy.

Here is the implementation of copy in the user interface.

3. After I1.separate().

And here is the implementation of separate in the user interface.

Swap Section

Pre Swap, with added prototype chain SI (Swap instance) => SP (Swap prototype) => SP2

4. After I1.swap(SP). This replaces the prototype P1 of I1 with SP

5. After I1.swapPrototype(SP). This replaces the prototype P1 of I1 with a new prototype SP, and propagates the change through the whole object graph. That is, every object that inherited from P1 now inherits from SP instead.

In the user interface, these operations show up both in swapping from the catalog, and also in local swap.

6. item.stringify() returns a string encoding the item

7. deserialize(str) returns the item encoded in the string str