为什么在AppleScript的,你能不能申报变量的引用局部处理程序? [英] Why, in AppleScript, can't you declare references to variables local to handlers?

查看:311
本文介绍了为什么在AppleScript的,你能不能申报变量的引用局部处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你为什么不能声明,除非引用的变量是全球范围内的使用变量的引用?请解释运行时内存或对象结构,导致了下列现象:

Why can't you declare and use references to variables unless the variable referenced is scoped globally? Please explain the runtime memory or object structure that leads to the following phenomenon:

脚本A失败:

on foo()        
    set l to {0}
    set lref to a reference to l
    return item 1 of lref
end foo

foo()

脚本B成功:

on run
    set l to {0}
    set lref to a reference to l
    return item 1 of lref
end run

脚本C成功:

on foo()        
    global l
    set l to {0}
    set lref to a reference to l
    return item 1 of lref
end foo

foo()

参见:<一href=\"http://stackoverflow.com/questions/15753161/how-do-you-efficiently-build-a-list-within-a-handler-in-applescript/15754609#15754609\">How你有效地AppleScript的一个处理程序中建立一个列表?和<一个href=\"http://stackoverflow.com/questions/3569847/why-cant-applescript-make-firstvalue-of-hash-into-type-reference-in-this-test-c?rq=1\">Why不能做的AppleScript哈希firstValue到本次测试code型参考?

推荐答案

由于参考是同样的事情作为对象说明,所以你不能做的东西的参考,是不是(或者由包含东西是不是)一个对象就AppleScript的关注。

Because a "reference" is the same thing as an object specifier, so you can’t make a reference to something that isn’t (or is contained by something that isn’t) an object as far as AppleScript is concerned.

一个全局变量是由顶级脚本对象所拥有的 - 它真的没有初始化的属性。 (您也可以到脚本属性的引用;它不具有严格全局)

A global variable is owned by the top-level script object -- it’s really a property with no initializer. (You can also have a reference to a script property; it doesn’t have to be strictly global.)

一个局部变量,另一方面,由处理程序,它是在呼叫帧拥有,并调用帧不在AppleScript的对象,因此,没有引用

A local variable, on the other hand, is owned by the call frame of the handler that it’s in, and call frames are not objects in AppleScript, therefore, no references.

这篇关于为什么在AppleScript的,你能不能申报变量的引用局部处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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