【问题标题】:How to correctly combine "dot notation" and "braces notation" in cocoascript (sketch)?如何在可可脚本(草图)中正确组合“点符号”和“大括号符号”?
【发布时间】:2015-11-15 01:38:05
【问题描述】:

在草图documentation 中指出点和大括号符号可以相互混合。甚至可以使用example

[[context.document currentPage] deselectAllLayers];

不幸的是,如果通过“运行自定义脚本”命令执行,此代码在草图中不起作用并产生错误:

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];

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

【问题讨论】:

    标签: cocoascript sketchapp


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 2017-04-05
      • 2016-01-08
      • 2015-05-29
      相关资源
      最近更新 更多