On Fri, Apr 11, 2008 at 12:17 PM, Lars Hansen <[EMAIL PROTECTED]> wrote:
>
>
> One motivation is that programmers are likely to prefer the Java-like
> syntax where the namespace (in its role as access control) shows
> up early:
>
> public var count =
> private var key =
>
> I really think this is the "right" syntax for variables. The syntax
>
> var private::key, private::foo, public::x, private::bar;
>
> is certainly workable and unambiguous but
>
> public var x;
> private var key, foo, bar;
>
> works better for me, because the access control is visible and
> separated from the names, because each phrase is shorter, and
> because I'm guaranteed to separate my privates from my publics.
Yep, I agree with this, too. I certainly wouldn't want to mandate
var public::x
in classes and wouldn't really want to write it myself. But there's
some value in having a single, canonical syntactic form that will work
everywhere. (If ES5 adds some kind of macro system, it would be more
useful.)
>
> Classes are sort of funny since you can consider a property name
> in a class both as a property on the instance (o.id) but also
> just as a scoped variable, inside all the methods of the class.
> If you're *really* into Java the former case disappears completely
> because there will be getter/setter pairs for everything ;) so the
> "scoped variable" case is completely dominant. I'm not sure
> that's wrong, and I think a variable declaration syntax is
> more natural than an object property syntax.
I agree with you on the natural syntax. I'm not too sure, however,
that the property name/scoped variable thing is much more than a
visual pun. (It would be different if classes were specified as
closure creation sugar.) In
class A {
public var x;
public function getX() x
}
I tend to think of the reference to 'x' as an elliptical form of
'this.x'. And then there is
class A {
public var x;
public static function brokenGetX() x
}
... where the "scoped variable" analogy doesn't work.
-Jon
_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss