>> example: make object! [
[ var1: 10
[ var2: var1 + 10
[ var3: now/time
[ set-time: does [var3: now/time]
[ calculate: func [value] [
[ var1: value
[ var2: value + 10
[ ]
[ ]
>>
>> example2: make object! third example
** Script Error: none is missing its value argument
** Near: calculate: func [value][
var1: value
var2: value + 10
]
>>
如何防止评估第三个例子?
答案 0 :(得分:1)
最好的方法可能是使用 construct / with - 它会根据现有对象创建一个对象。
根据示例对象和额外字段创建对象:
example2: construct/with [extra-field: 999] example
或制作一个只有相同字段的
example2: construct/with [] example
答案 1 :(得分:1)
您还可以利用Rebol的对象原型设计:
example2: make example []
或附加字段
example3: make example [
var4: now/date
set-date: does [var4: now/date]
]
或替换字段
example4: make example [
calculate: func [value] [
var1: value
var2: value + 20
]
]