在IO中将字符串视为对象名称的方法?
在 Io 中,有一个 getSlot() 方法,它允许您将字符串转换为槽引用,但是是否有类似的方法来获取对象的引用?例如:
myObject := Object clone
myObject myMethod := method("Hello World!" println)
targetObject := "myObject"
a := getObject(targetObject) clone
getObject()
不存在,那么什么可以代替它,使得“a”最终成为“myObject”的克隆?
In Io, there is a getSlot()
method which allows you to convert a string to a slot reference, but is there something similar to get a reference to an Object? For example:
myObject := Object clone
myObject myMethod := method("Hello World!" println)
targetObject := "myObject"
a := getObject(targetObject) clone
getObject()
doesn't exist, so what can go in its place such that "a" ends up being a clone of "myObject"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你居然自己回答了!
在 Io 中,你有带有槽的对象,这些槽本身可以是对象。
因此,为了让您的代码正常工作,您只需在当前作用域上调用 getSlot 即可。
You actually answered yourself!
In Io you have objects which have slots, and these slots can be objects themselves.
So for your code to work properly you simply call getSlot on the current scope.