我试图通过使用由可变数量的用户输入字段组成的字符串来调用 Coffee 脚本中类实例的方法。假设我们有一个“表面”实例,我们应该在其上调用一个绘制特定图形的方法。这是 CoffeeScript 中的代码:
dojo.ready ->
dojoConfig = gfxRenderer: "svg,silverlight,vml"
surface = dojox.gfx.createSurface("dojocan", 500, 400)
/ The user's input values are stored in an array
/ and then concatenated to create a string of this pattern:
/ formula = "createRect({pointX,pointY,height,width})"
/ Now I should apply the string "formula" as a method call to "surface" instance
surface."#{formula}".setStroke("red")
/ ?? as it would be in Ruby , but .... it fails
我见过所有类似的问题,但我找不到在 Coffee Script 中实现它的答案。
感谢您的时间 。