我正在使用 Javascript 进行 InDesign 脚本编写。
我有一个图像对象,想知道它的边界(用户看到的边界)-
bounds = (geometricBounds in image.parent)? image.parent.geometricBounds: image.geometricBounds;
返回ReferenceError - GeometricBounds未定义
。当图像的父级是 Oval 对象时会出现此错误(因此,我知道 Oval 对象存在 GeometricBounds 属性)。
问题出在 (geometricBounds in image.parent)
中,因为当我警告此语句时,我得到了相同的错误。我肯定错过了一些东西 - 因为如果这不是一个属性那么我应该简单地得到一个 false。
有人知道为什么会发生这种情况吗?
最佳答案
in
运算符检查属性名称作为字符串(在您的情况下,它正在查找名为 geometricBounds
的变量 - 它可能包含属性名称字符串 -显然没有在任何地方声明):
bounds = ('geometricBounds' in image.parent)? image.parent.geometricBounds: image.geometricBounds;
关于JavaScript/InDesign : Check if Object has certain property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16735684/