Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is casting Object(null) not null?

When you cast null to an object using Object(null), the result is an object.

When you cast undefined to an object using Object(undefined), the result is an object.

But saying null as Object or undefined as Object remains null.

Why is this? I can't find anything in the documentation about this.

The objects that result from these casts can have properties set on and read from them. It's as if the cast created information, or removed whatever special information the null and undefined values have. But there's no indication in the AS3 documentation that the null and undefined special types are actually objects.

like image 212
ivanreese Avatar asked Dec 27 '25 17:12

ivanreese


1 Answers

There is a difference between the two casting techniques. Here is a good read on it: http://upshots.org/actionscript-3/as3-casting-objects

Basically, Object(null) actually converts null into an Object while "as" attempts to see if null can be treated as an Object, which it cannot.

like image 164
Pixel Elephant Avatar answered Dec 30 '25 22:12

Pixel Elephant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!