UMD规范

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

//  普通的模块
!( function( root, name, factory) {
    if ( typeof define === 'function' && define.amd) {
        define( name, factory);
    } else if ( typeof exports === 'object') {
        module.exports = factory();
    } else {
        root[name] = factory();
    }
})( this, 'run', function () {
    function run () {
        return 'this is run function!';
    }
    return run;
});

//  载入第三方模块的模块
!( function( root, name, factory) {
    if ( typeof define === 'function' && define.amd) {
        define( name, ['lodash','moment'], factory);
    } else if ( typeof exports === 'object') {
        module.exports = factory( require('lodash'), require('moment'));
    } else {
        root[name] = factory();
    }
})( this, 'run', function ( _, moment) {
    console.log( _);
    console.log( moment);
    function run () {
        return 'this is run function!';
    }
    return run;
});

 

转载于:https://my.oschina.net/fattypanda/blog/1537376

你可能感兴趣的:(javascript,python)