Reputation: 2754
The new function below doesn't work if Obj is local. If I remove it from /local it works. So what to do to make it work with a local Obj thanks ? Sure not hard for you.
Person: make object! [
Person: func[FirstName LastName][
Self/FirstName: FirstName
Self/LastName: LastName
Print Self/FirstName
Print Self/LastName
]
FirstName: ""
LastName: ""
]
new: func[Class [Object!] Param-Block [block!] /local Obj][
Constructor: to-word pick pick Class 1 2
Obj: Make Class []
params: copy ""
foreach param Param-Block [
if string? param [
param: rejoin [{"} param {"}]
]
append params param
append params " "
]
do rejoin [{do get in Obj Constructor} { } params]
Obj
]
;FOR TEST
John: new Person["John" "Doe"]
Would give
>> probe John
make object! [
Person: func [FirstName LastName][
Self/FirstName: FirstName
Self/LastName: LastName
Print Self/FirstName
Print Self/LastName
]
FirstName: ""
LastName: ""
]
>>
That is FirstName and LastName are "" instead of "John" "Doe"
Upvotes: 0
Views: 186
Reputation: 4886
This works ...
rebol []
Person: make object! [
Person: func [ names] [
Self/FirstName: names/1
Self/LastName: names/2
]
FirstName: copy ""
LastName: copy ""
]
new: func [class [object!] param-block [block!]
/local obj constructor
] [
constructor: second first class
obj: make class []
do get in obj constructor copy param-block
obj
]
test: new person [ "John" "Doe" ]
probe test
make object! [
Person: func [names][
Self/FirstName: names/1
Self/LastName: names/2
]
FirstName: "John"
LastName: "Doe"
]
test2: new person [ "Dick" "Nixon" ]
probe test2
make object! [
Person: func [names][
Self/FirstName: names/1
Self/LastName: names/2
]
FirstName: "Dick"
LastName: "Nixon"
]
Upvotes: 3