views:

249

answers:

2

In Flex 3,

var anInstance : MyClass = new MyClass();
with (anInstance)
{
    property1 = "fred";
    property2 = 5;
    propert3 = 7;
}

does NOT flag "propert" as a non-existent property name. I thought this was a remainder of the evil JavaScript object behavior (referring to a property name of an object implicitly creates it), but it seems to be a side-effect of the "with".

This makes me very sad as the "with" was a little reminder of Delphi (except it works correctly there).

Am I missing something here?

+3  A: 

From reading the documentation:

Actionscript apparently bubbles out for scope resolution on embedded variables (not surprising, since the syntax doesn't require an explicit dereference symbol like "." or "->" to indicate which variable names should be "withed".) So you effectively are creating a variable at global scope named propert3.


EDIT after thinking about why this "problem" exists -

Javascript is the epitome of non-strict typing. And Actionscript, being a strict superset of Javascript, can't enforce strict typing except as declared by its own extensions to the language - which means it must support untyped variables.

le dorfier
That documentation link is local to your machine. I think you might mean http://livedocs.adobe.com/flex/3/langref/index.html
Richard Szalay
Shouldn't the compiler then give at least a warning for the variable propert3 not being declared in advance? ... (some minutes testing) ... Nope, it does not. Furthermore, there is no runtime error, either.
David Hanak
@Richard - thanks - link fixed.
le dorfier
I hate JavaScript. I enhanced a huge Dojo/Scriptaculous application and I really came to hate loose, squishy languages (I hated Perl before that).ActionScript 3 is typed tightly enough that I can handle it. Evidently, it has some vestigial squishyness besides Objects.Thanks
Richard Haven
+1  A: 

Some classes are dynamic (e.g. movieclip) and can have properties added to them at runtime:

http://flexblog.faratasystems.com/?p=95

Iain
Ahhhhh!!!! I hate classes that are not closed (except to inheritance). That's one reason I don't do Ruby.What's the point of strict typing if it does not catch freaking membership!I'm done ranting now.
Richard Haven