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

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

问题描述

有谁知道为什么这个AppleScript的作品?我不明白为什么。该脚本生成包含相同的消息三个对话框:你好。我有两个问题:

1)怎样才能j和K定义之前,我被设置为引用我?

2)TEST2为什么不定义R参考了我?

  Test1上()
  返回得到一个参考我
最终测试上运行
  集合的J为TEST1()
  令k向我参考
  我设置为你好
  显示对话框Ĵ
  显示对话框ķ
  TEST2()
运行结束在TEST2()
  我设置为现在看这里
  集合R向我参考
  显示对话框 - [R
结束TEST2

注:脚本编辑器2.7版本和AppleScript的版本是2.4


解决方案

  1. 您只能创建一个对象的属性或元素[S],或全局变量(一个恼人的错误功能,表现得像设计不当的属性),而不是局部变量的引用。例如这些所有的工作:

     上TEST2()
        集合X为{我:现在看这里}
        集合R的基准为i x的
        显示对话框 - [R
    结束TEST2TEST2()在TEST3()
        集合X到{现在看这里}
        集R为参考x的第1项
        显示对话框 - [R
    结束TEST3TEST3()在TEST4()
        脚本点¯x
            物业我:现在看这里
        结束脚本
        集合R的基准为i x的
        显示对话框 - [R
    结束TEST4TEST4()
    物业我:现在看这里在TEST5()
        集合R向我参考
        显示对话框 - [R
    结束TEST4TEST5()


  2. 这是隐性或显性的运行处理程序中的所有变量都是全局的(另一种错误的特征),除非明确声明本地。这两项错误特性的结合就是为什么你的运行处理工程为例,虽然它看起来像它不应该。


是啊,这是怎样的一个janky语言。但看看光明的一面:它比C指针headachey更不用说

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) How can j and k be set to reference i before i is defined?

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

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

解决方案

  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()
    

  2. 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.

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天全站免登陆