seajs

zyip發表於2014-04-18

 

m1.js

define('mysea/m1',['mysea/m3','mysea/fun1'],function(require,b,module){

    var fun1=require('mysea/fun1');
    console.log(xyz); // the variable xyz if from fun1.js, and also it is a global variable

    var m2=require('mysea/m2');

    console.log('hello sea mysea/m1');

    window.exports1=module.exports={
        fun1:function(){
            console.log('fun1');
        }
    };
    console.log('end of mysea/m1');

    var m3=require('mysea/m3');
    return {'v':'return value of myesea/m1'}
});


define('mysea/m2',[],function(require,b,module){

    console.log('hello sea mysea/m2');

    module.exports={
        fun1:function(){
            console.log('fun1 in m2');
        }
    };
    console.log('end of mysea/m2');

    return {'v':'return value of myesea/m1'}

});

m3.js

define('mysea/m3',[],function(require,b,module){

    console.log('hello sea mysea/m3');

    module.exports={
        fun1:function(){
            console.log('fun1 in m3');
        }
    };
    console.log('end of mysea/m3');
});

 

fun1.js

console.log('a line in fun1');


define(
function fun1(){

    console.log('fun1.js is running');

    return {'name':'fun1'};

}
);

var xyz='xyz';

 

index.htm

seajs.use("mysea/m1");