如何在 cocoascript (sketch) 中正确组合 "dot notation" 和 "braces notation"?

How to correctly combine "dot notation" and "braces notation" in cocoascript (sketch)?

草图 documentation it's stated that dot and braces notations can be mixed with each other. It's even an example 可用:

[[context.document currentPage] deselectAllLayers];

不幸的是,此代码在 sketch 中不起作用,如果由 "run custom script" 命令执行,则会产生错误:

SyntaxError: Unexpected identifier 'currentPage'. Expected either a closing ']' or a ',' following an array element..
Plugin “untitled script”, line 2.
»   [context.document currentPage]; «Error in command untitled script Script at path (null) does not contain a handler function named: onRun
Script executed in 0.023666s

这可以通过添加额外的 () 来避免:

[[(context.document) currentPage] deselectAllLayers];

为什么会这样?是否有任何文档可以准确地混合大括号和点符号?是一些错误还是预期的行为?

在我看来这是一个错误,但在 Sketch 文档中。除了你展示的这个案例,我找不到任何其他例子,在同一个语句中一起使用点和大括号符号,没有括号。

例如,有关选择的文档页面告诉您可以使用以下代码取消选择所有内容:

var doc = context.document
[[doc currentPage] deselectAllLayers]

按照此 link 并查看 清除选择 header: http://bohemiancoding.com/sketch/support/developer/02-common-tasks/01.html

即使是他们的示例插件也不会混合使用这两种表示法,如您在此处所见:https://github.com/BohemianCoding/ExampleSketchPlugins/blob/master/Hello%20World/Hello%20World.sketchplugin/Contents/Sketch/script.cocoascript.

在该示例中,context.document 在大括号内使用之前也被分配给一个新变量。