|REBOL 3 Docs||Guide||Concepts||Functions||Datatypes||Errors|
|TOC < Back Next >||Updated: 6-Feb-2009 Edit History|
new-object: make parent-object new-values
The first argument, parent-object , is the parent object from which the new object is made. If no parent object is available, as when defining an initial object, use the object! datatype, as shown below:
new-object: make object! new-values
The second argument, new-values , is a block that defines additional variables and initial values for the new object. Each variable that is defined within the block is an instance variable of the object. For example, if the block contained two variable definitions, then they would be variables of the object:
example: make object! [ var1: 10 var2: 20 ]
The example object has two variables that hold two integers.
The block is evaluated, so it can include any type of expression to compute the values of the variables:
example: make object! [ var1: 10 var2: var1 + 10 var3: now/time ]
Once an object has been made, it can serve as a prototype for creating new objects:
example2: make example 
The above example makes a second instance of the example object. The new object is a clone of the first object. New values for the second object are set in the block:
example2: make example [ var1: 30 var2: var1 + 10 ]
In the example above, the example2 object has different values than the original example object for two of its variables.
The example2 object can also extend the object definition by adding new variables to it:
example2: make example [ var4: now/date var5: "example" ]
The result is an object that has five variables: Three that came from the original object, example , and two new ones.
The process of extending the definition of an object can be repeated any number of times.
You can also create an object that contains variables that are initialized to some common value. This can be done using a cascaded set of word definitions:
example3: make object! [ var1: var2: var3: var4: none ]
In the example above, the four variables are set to none! within the new object.
To summarize, the process of creating an object involves these steps:
|TOC < Back Next >||REBOL.com - WIP Wiki||Feedback Admin|