在定义 Applescript 对象之前如何引用它们? [英] How can Applescript objects be referenced before they are defined?

查看:22
本文介绍了在定义 Applescript 对象之前如何引用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道为什么这个applescript 有效?我不理解为什么.该脚本生成三个包含相同消息的对话框:Hi There".我有两个问题:

Does anyone know why this applescript works? I do not understand why. The script generates three dialog boxes containing the same message: "Hi There". I have two questions:

1) 如何在定义 i 之前将 j 和 k 设置为引用 i?

1) How can j and k be set to reference i before i is defined?

2) 为什么 r 不引用 test2 中定义的 i?

2) Why does not r reference the i defined in test2?

on test1()
  return get a reference to i
end test

on run
  set j to test1()
  set k to a reference to i
  set i to "Hi there"
  display dialog j
  display dialog k
  test2()
end run

on test2()
  set i to "now see here"
  set r to a reference to i
  display dialog r
end test2

注意:脚本编辑器版本为 2.7,AppleScript 版本为 2.4.

Note: The Script Editor is Version 2.7 and the AppleScript Version is 2.4.

推荐答案

  1. 您只能创建对对象属性或元素[s] 或全局变量的引用(一个恼人的错误特性,其行为类似于设计不良的属性),而不能创建对局部变量的引用.例如这些都有效:

  1. You can only create references to an object property or element[s], or to global variables (an annoying mis-feature which behave like badly designed properties), not to local variables. e.g. These all work:

on test2()
    set x to {i:"now see here"}
    set r to a reference to i of x
    display dialog r
end test2

test2()

on test3()
    set x to {"now see here"}
    set r to a reference to item 1 of x
    display dialog r
end test3

test3()

on test4()
    script x
        property i : "now see here"
    end script
    set r to a reference to i of x
    display dialog r
end test4

test4()


property i : "now see here"

on test5()
    set r to a reference to i
    display dialog r
end test4

test5()

  • 隐式或显式 run 处理程序中的所有变量都是全局的(另一个错误功能),除非明确声明 local.这两个错误功能的组合就是您的 run 处理程序示例工作的原因,即使它看起来不应该.

  • All variables within an implicit or explicit run handler are global (another mis-feature), unless explicitly declared local. The combination of those two mis-features is why your run handler example works, even though it looks like it shouldn't.

    是的,这是一种简陋的语言.但是从好的方面来看:它仍然没有 C 指针那么令人头疼.

    Yeah, it's kind of a janky language. But look on the bright side: it's still less headachey than C pointers.

    这篇关于在定义 Applescript 对象之前如何引用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆