On Thursday, November 3, 2011 10:50:28 PM UTC+8, Arian Stolwijk wrote:
>
> I guess, since the module is still wrapped in a define function, define 
> can scan the .toString of the function for require() calls, and load the 
> modules, when they're loaded, call the function and the require() calls 
> will work because those dependencies are loaded too.
>
> It looks a lot like a subset of AMD with some extras.
>
>
@Arian: thanks very much for your explanation. Yes, you are right. I use 
the function.toString() to scan the dependencies. But it is different from 
RequireJS. SeaJS is not the same as the CommonJS Simple Wrapper in 
RequireJS, considering the following code:

// foo.js
define(function(require, exports) {
  console.log(1);
  exports.name = 'foo';
});

// main.js
define(function(require, exports) {
  console.log(2);
  exports.foo = require('./foo');
});

If we load main.js with RequireJS:

<script src="require.js" data-main="main"></script>

The console log is: 1, 2

With SeaJS:

<script src="sea.js" data-main="main"></script>

The console log is: 2, 1


In RequireJS, the execution of module factory is very early. So we get 1 in 
console first.

But in SeaJS, the module factory is called only at the first "require" to 
it. This behavior is similar to CommonJS Modules/1.1.1, In my opinion,  it 
is more lazy and better than RequireJS.





-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to