actionscript(flex):如何知道对象的属性是否存在(或定义)? [英] actionscript (flex): how to know whether a property of object exists (or defined)?

查看:24
本文介绍了actionscript(flex):如何知道对象的属性是否存在(或定义)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名尝试使用 Flex 的 Java 开发人员.这是我的问题:

I am a Java developer who tries Flex. Here is my problem:

我将 actionScript 对象视为 hashmap,但是当对象没有属性时,它会给出异常:没有这样的变量.

I behave actionScript objects as hashmap but when the object do not have the property it gives exception: No such variable.

在这里,我希望它给我空值,而不是给出异常.那么你知道有没有办法处理它,即检查是否为对象定义了属性.

Here I expect it gave me null, instead of giving exception. So do you know is there a way to handle it, namely check if the property is defined for object.

trace( obj["2008-02"] )//给出异常

trace( obj["2008-02"] ) // gives exception

推荐答案

使用类似的东西

if (myObject.hasOwnProperty("propertyName"))

检查属性是否存在.

另请查看此处.

这篇关于actionscript(flex):如何知道对象的属性是否存在(或定义)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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