[英]Javascript/InDesign: Check if Object has certain property
I'm using Javascript for InDesign scripting. 我正在使用Javascript进行InDesign脚本编写。
I have an image object and want to know it's bounds (the one that the user sees) - 我有一个图像对象,想知道它的边界(用户看到的那个) -
bounds = (geometricBounds in image.parent)? image.parent.geometricBounds: image.geometricBounds;
returns ReferenceError - geometricBounds is undefined
. 返回ReferenceError - geometricBounds is undefined
。 This error comes when the parent to the image is an Oval object (So, I know geometricBounds property is there for an Oval object). 当图像的父级是Oval对象时,会出现此错误(因此,我知道geometryBounds属性适用于Oval对象)。
The problem is in (geometricBounds in image.parent)
because when I alerted this statement, I got the same error. 问题在于(geometricBounds in image.parent)
因为当我提醒这个语句时,我得到了同样的错误。 I'm surely missing something - because if this is not a property then I should simply get a false. 我肯定错过了一些东西 - 因为如果这不是一个属性那么我应该只是弄错了。
Any one knows why this is happening? 任何人都知道为什么会这样吗?
in
运算符检查属性名称是否为字符串(在您的情况下,它正在查找名为geometricBounds
的变量 - 可能包含属性名称字符串 - 显然未在任何地方声明):
bounds = ('geometricBounds' in image.parent)? image.parent.geometricBounds: image.geometricBounds;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.