Namespace/Package Creation (Objects)

30 views
Skip to first unread message

Si Robertson

unread,
Mar 12, 2015, 10:55:06 AM3/12/15
to streng...@googlegroups.com
Hi,

Something caught my attention while reading through the Strong Mode Proposal, regarding the creation of object properties.

As we know, a common way to avoid naming conflicts in JavaScript is to create object literals (treating them as namespaces) and populate them with functions and constructors, the Closure Library is a good example of this. Based on what I have read in the proposal, this is going to become quite cumbersome when using strong mode. It seems we will have to (a) define all object properties ahead of time in one lumpy declaration, or (b) use the verbose Object.defineProperty function everywhere.

There is also the issue of "static" properties and functions that are typically defined like FooClass.APPLE=1 ... FooClass.BANANA=2 etc on constructors (or classes in ES6).

Does any have any thoughts regarding this?

Andreas Rossberg

unread,
Mar 13, 2015, 6:37:59 AM3/13/15
to Si Robertson, streng...@googlegroups.com
Yes: a central assumption for strong mode is that it is meant for code that is able and willing to fully embrace ES6. And in this case that means using modules for such patterns. They should provide similar functionality in a more general and more natural manner. It won't always be feasible to port existing code to strong mode, but that wasn't a goal (as long as you can still _use_ existing code from it).

Admittedly, modules aren't done yet in V8 (or any browser), but we are working on that. :)

/Andreas


Si Robertson

unread,
Mar 13, 2015, 10:51:29 AM3/13/15
to streng...@googlegroups.com, retrom...@gmail.com
Ah, modules. My bad. I should have realized those would be the solution, they are something I'm actually looking forward to using.
Reply all
Reply to author
Forward
0 new messages