Rebol 和 /local 对象
如果 Obj 是本地的,下面的新函数将不起作用。如果我将它从 /local 中删除它就可以了。那么如何才能使其与本地 Obj 一起工作呢?谢谢?当然对你来说并不难。
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"]
会给出
>> probe John
make object! [
Person: func [FirstName LastName][
Self/FirstName: FirstName
Self/LastName: LastName
Print Self/FirstName
Print Self/LastName
]
FirstName: ""
LastName: ""
]
>>
那是名字和姓氏是“”而不是“John”“Doe”
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有效...
This works ...