Right but the compiler is already *hoisting*, which means it moves all
variable declarations to the top of the function. For example, the following
code compiles even though the initial trace() function for the num variable
happens before the num variable is declared:

trace(num); // NaN
var num:Number = 10;
trace(num); // 10

The compiler will not, however, hoist any assignment statements. But it
could use the assignment statements to dynamically type the variable. So
then:

var x = new A();

var x;
x = new A();

would be the same

I think for the backwards compatibility issue it could be handled with a
compiler option. more important than getting around the issues would be
would you use it?

On Sat, Jun 19, 2010 at 11:35 PM, Rick Genter <rick.gen...@gmail.com> wrote:

>
>
>
> On Jun 19, 2010, at 9:31 PM, dorkie dork from dorktown wrote:
>
> > Currently if you leave a variable untyped it remains untyped. So to
> > type something I have to include the type in the declaration like so:
> >
> > var myInstance:ClassA = new ClassA();
> >
> > but as you can see the type is specified in the instantiation! so I'm
> > thinking that by default when a variable doesn't specify a type then
> > it should be typed intrinsically by the compiler to the class that is
> > instantiating it.
> >
> > So these two examples would be the same:
> > var myClass:ClassA = new ClassA();
> > var myOtherClass:ClassB = new ClassB();
> >
> > var myClass = new ClassA();
> > var myOtherClass = new ClassB();
> >
> > you'd still be able to cast it but you wouldn't have to. so the
> > default behavior of AS3 would be to do the best practice not the worst
> > practice.
> >
> > jp
>
> If you did that then you would break backwards compatibility. Also, it
> means the following two code fragments would behave differently:
>
> var x = new A();
>
> var x;
> x = new A();
>
> I think that's a bad idea.
> --
> Rick Genter
> rick.gen...@gmail.com <rick.genter%40gmail.com>
>
>  
>

Reply via email to