On Nov 17, 2011, at 10:17 AM, Jason Orendorff wrote: > On Thu, Nov 17, 2011 at 10:40 AM, David Herman <[email protected]> wrote: >> This isn't about scope, it's about at what point they're initialized. If you >> write: >> >> let x = new C(); >> let C = class /* whatever */; >> >> you won't get a scope error but a runtime initialization error. Whereas if >> you write: >> >> let x = new C(); >> class C { ... } >> >> it'll work fine. >> >> I'm with Arv 150% on this. > > I'm with Allen. If ES classes can contain any initialization code,
That's a big "if" right now. The only way I see this happening is via static data property initialisers. The definition of static properties (of any kind) is not observable on the class or its prototype if |this| is verboten in initialiser expressions (for |this| read any keyword that allows access to the class constructor or prototype). Of course, initialiser expressions could have side-effects in the heap (increment a global counter, e.g.). That's considered bad practice and I'm not sure worrying about it trumps the classes-as-sugar argument for hoisting: function declarations hoist today, people write constructors this way (most of the time), porting to classes which desugar this way suggests class declarations should hoist just as functions do to. /be > I think it should run in program order, interleaved with top-level > statements. Anything else is just confusing. > > Note that classdefs in Ruby and Python aren't hoisted, and nobody > complains. In those languages classdefs very often contain procedural > code, for many purposes. > > class Card # Ruby > attr_accessor :rank, :suit # macro-like > end > > class File: # Python > size = property(get_size) # create property descriptor > if os.name == 'posix': # ifdef-like > ... posix-only methods ... > > -j > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

