Hacker News new | ask | show | jobs
by Roboprog 3700 days ago
Thanks, I had not seen that before. Interesting trick: Call a "registration" function with a string array (of dependencies) and an anonymous function (IIFE) with parameters for each dependency which the registration function injects. Thus, the dependencies are accessed as closures over the outermost func's params, rather than as globals.

E.g. -

    define( [ 'jQuery' ], function ( $ ) { ... return { ... } } )
where the 1st elipses are all the private/setup code, and the second elipses are whatever methods/properties the module exports. (this dummy only wants jQuery, but the list can be longer)