REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Objects: Prototype Objects

Pending Revision

This document was written for R2 and has yet to be revised for R3.

Any object can serve as a prototype for making new objects. For instance, the lily account object previously defined can be used to make new objects with a line such as:

maya: make lily []

This makes an instance of an object. The object is a copy of the customer object and has identical values:

print lily/balance
-$890.00
print maya/balance
-$890.00

You can modify the new object while making it by providing the new values within the definition block:

maya: make lily [
    first-name: "Maya"
    balance: $10000
]

print maya/balance
$10000.00
maya/deposit $500

print maya/balance
$10500.00
print maya/first-name
Maya

The lily object serves as a prototype for creating the new object. Any words that are not redefined for the new object continue to have the values of the old object:

print maya/last-name
Lakeswimmer

New words are added to the object in a similar way:

maya: make lily [
    email: maya@example.com
    birthdate: 4-July-1977
]


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin