Is there any difference between those three declarations?
var x;
var y:Object;
var z:*;
Is there anything in AS that’s not an Object?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
var x;andvar x:*;mean precisely the same thing to the compiler — the variable can accept any type. Use:*rather than omitting type to enhance readability of your code.Practically,
var x:Object;is equivalent, since as you noted everything descends from Object. However, the compiler treats it different, and it tends to be slightly slower if you’re accessing non-Object properties. Additionally, as noted by the other answers, attempting to assignundefinedto an Object will automatically cast it tonull.I recommend using
:*if your variable can accept more than one unrelated type of value, and using:Objectwhen using an Object as an associative array.