如果试验对象是在ActionScript中定义 [英] Test if an object is defined in ActionScript
问题描述
在ActionScript中,你怎么能测试一个对象被定义,就是不为空?
测试如果一个对象被定义
这在AS2和AS3,是最可靠的方法来测试,如果一个对象的值。
如果(OBJ!= NULL){
doSomethingWith(OBJ);
}
它也是最可靠的方法来测试对象的属性和读取它同前pression:
如果(ARR [0] = NULL和放大器;!&放大器;常用3 [0]> 5){
doSomethingWith(ARR [0]);
}
测试对象是否为空
有null和undefined之间的差异,但如果你不关心你可以做一个正常的比较之间的任何一个,因为他们比较平等的:
如果(OBJ == NULL){
doSomethingWith(OBJ);
}
是相同的
如果(OBJ ==未定义){
doSomethingWith(OBJ);
}
如果你在乎的区别,使用===或!==操作符,不会进行转换。
如果(OBJ ===未定义){
// OBJ从未分配一个值
}
否则,如果(OBJ === NULL){
// OBJ被明确设置为null
}
其他 {
doSomethingWith(OBJ);
}
In ActionScript, how can you test if an object is defined, that is, not null?
test if an object is defined
This works in AS2 and AS3, and is the most reliable way to test if an object has a value.
if (obj != null) {
doSomethingWith(obj);
}
Its also the most reliable way to test an object's property and read it in the same expression:
if (arr[0] != null && arr[0]>5) {
doSomethingWith(arr[0]);
}
test if an object is null
There's a difference between null and undefined, but if you don't care you can just do a normal comparison between either one because they compare equal:
if (obj == null) {
doSomethingWith(obj);
}
is the same as
if (obj == undefined) {
doSomethingWith(obj);
}
If you care about the difference, use the === or !== operator, which won't convert them.
if (obj === undefined) {
// obj was never assigned a value
}
else if (obj === null) {
// obj was explicitly set to null
}
else {
doSomethingWith(obj);
}
这篇关于如果试验对象是在ActionScript中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!