gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:34:16 24 4
gpt4 key购买 nike

素描documentation据说点号和大括号符号可以相互混合。它甚至是一个 example可用:

[[context.document currentPage] deselectAllLayers];

不幸的是,这段代码在 sketch 中不起作用,如果通过“运行自定义脚本”命令执行,则会产生错误:

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]

点击此链接并在清除选择 标题下查看: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 在大括号内使用之前也被分配给一个新变量。

关于cocoascript - 如何在 cocoascript (sketch) 中正确组合 "dot notation"和 "braces notation"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32134721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com