Hacker News new | past | comments | ask | show | jobs | submit login

Not sure if you'd have any thoughts on this matter...

The JavaScript community as a whole (seen especially in the direction of node.js + NPM) is moving away from global namespaces and toward the "module pattern" and dependency injection (note: I had no idea what those terms really meant 6 months ago).

Presently, Joose3 goes against that grain. For example, if in a node.js script you:

   require('joose')
   if (Joose) { console.log(true) } // prints true!
Basically, the global namespace gets auto-populated with "Joose" and a chain of namespaces below that. This is very Perl/Moose-like, of course.

When you define classes, roles, etc. you get similar behavior:

   Joose.Class('MyClass', {...})
   if (MyClass) { console.log('effectively stubbed in a global namespace!') }
   // does log that text to console, as Joose.Class() behaves that way
And in fact, Joose3 encourages you to embrace that behavior (with `use:` builders and lots of discrete files) to arrive at a network of cross-referenced namespaces which altogether form a library, and API usually.

To go with the flow, and especially to take advantage of emerging module specs like AMD (commonjs thing), a redesigned Joose (i.e. Joose4) needs to eschew global namespaces entirely:

   var myJuice = require('joose')
   ...
   // There should be no tie to a "Joose" namespace as such
But how to do that, and elegantly?

Any wisdom from the Perl community in that regard? Maybe someone else has been trying to port Perl stuff to JavaScript/node.js and has found the perfect formalism for translating from global namespaces -> module pattern + dependency injection? Know any Moose wizards that would be willing to help explore this matter?




I haven't written a lot of Joose code, but I use anonymous classes and store their constructors as attributes of a lexically scoped object I inject where I need it, so as to avoid global pollution. So far it works nicely.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: