incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Mueller <pmue...@gmail.com>
Subject Re: CommonJS and AMD (and, not or)
Date Tue, 13 Dec 2011 21:43:02 GMT
On Tue, Dec 13, 2011 at 14:56, James Burke <jrburke@gmail.com> wrote:

> On Tue, Dec 13, 2011 at 11:25 AM, Brian LeRoux <b@brian.io> wrote:
> > Looks rad. I'm curious what an AMD plugin vs the same plugin authored
> > in CJS style would look like. Just a hello world.
>
> Usually the only difference for coding a callback plugin in AMD or CJS
> would be a define wrapper in the AMD case:
>
> define(function(require, exports, module){
>    //CJS stuff goes in here.
> });
>

This is using the anonymous module pattern, instead of naming the module by
passing an id as the first parameter to define().  Unfortunately, it seems
difficult to convert this pattern into almond usage, as almond requires
that you have an id as the first parameter (as near as I can tell, for a
normal module).  To use an anonymous module with almond, you have to
rewrite the module to add the id at build time (ick!) or you could resort
to horrible, hideous hacks (you don't want to know!).

A named, wrapped CJS module as AMD would look like:

define(moduleId, function(require, exports, module){
   //CJS stuff goes in here.
})

I'm not sure what breaks when you DO use an id; is that an issue with
dynamic loading?

-- 
Patrick Mueller
http://muellerware.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message