简体   繁体   English

Javascript / InDesign:检查对象是否具有某些属性

[英]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.

相关问题 如何检查javascript对象是否具有某个属性 - How to check if a javascript object has a certain property Javascript:检查多维数组中的对象是否具有特定属性,然后删除该对象 - Javascript: check if an object within a multidimensional array has a certain property and then remove that object javascript-检查对象是否具有子属性 - javascript - check if object has child property JavaScript 中的对象具有属性深度检查 - Object has-property-deep check in JavaScript JavaScript - 如果 object 属性具有特定值,则创建一个 object 键数组 - JavaScript - Create an array of object keys if the object property has certain value javascript:检查对象是否具有特定元素或属性的最佳方法? - javascript: best way of checking if object has a certain element or property? 在 JavaScript 中检查数组是否包含具有特定属性值的对象? - Check if an array contains an object with a certain property value in JavaScript? 如果Object属性具有某些定界符,如何分割JavaScript数组元素 - How to Split JavaScript Array Elements if an Object property has certain delimitter 如何检查 JavaScript 对象是否具有以特定字符串开头的属性名称? - How to check if a JavaScript Object has a property name that starts with a specific string? 如何检查 object 在 JavaScript 中是否具有特定属性? - How do I check if an object has a specific property in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM