zoukankan      html  css  js  c++  java
  • seajs使用记

    1、seajs使用外部依赖(第三方工具库,譬如jQuery)

             错误做法:

    define(function(require, exports, module){
       
        //  require可以下载外部依赖,但是他不能将其解析为seajs自身的模块,所以不能这样使用。
        var $ = require('../../depency/3rd_lib/jquery.js');
    
        $('#hi').html("aaaaaa");
       
    });

            正确做法1:

                  

    index.html
    
    <html>
         <head>
            <title>sea demo</title>
            <!-- <script type="text/javascript" src="../depency/3rd_lib/jquery.js"></script> -->
            <script type="text/javascript" src="../depency/3rd_lib/sea-debug.js"></script>
        </head>
    
    <body>
    
    <div id="hi">
    
    </div>    
    
    <script type="text/javascript">
        seajs.use('../static/test/seaUtil.js', function(){
             seajs.use('../static/test/seajsDemo.js');    
        });
    
    </script>
        
    
    </body>
    </html>
    
    
    seaUtil.js
         
           define(function(require, exports, module){
        
        /**
         *  require可以下载外部依赖,但是他不能将其解析为seajs自身的模块,所以不能这样使用。
         *  外部依赖引入推荐做法:
         *     1、将外部依赖单独放到一个seajs文件模块中引入,在首页seajs.use的callback里use其他模块,在callback中引入其他初始模块可以防止依赖未引入时使用
         *     2、将外部依赖放在首页HTML中加载,在seajs文件模块中直接使用
         */ 
        
        require('../../depency/3rd_lib/jquery.js');
    
        // $('#hi').html("aaaaaa");
       
    });
    
    seajsDemo.js
         define(function(require, exports, modeule){
    
        var seaUtil = require('./seaUtil');
    
        eBase = window.eBase = window.eBase || {}; 
        
        app = window.app = window.app || {};
    
        
         
    
    
        $.extend(eBase, {
            sayHello: function(){
                alert('hello , gray boy @');
            }
        });
    
        app.userManager = app.userManager || {};
    
        
    
    });
                        

         正确做法2:

              

    index.html
    
         <html>
    <head>
    <title>sea demo</title>
    <script type="text/javascript" src="../depency/3rd_lib/jquery.js"></script>
    <script type="text/javascript" src="../depency/3rd_lib/sea-debug.js"></script>
    </head>
    
    <body>
    
    <div id="hi">
    
    </div>    
    
    <script type="text/javascript">
        seajs.use('../static/test/seaUtil.js', function(){
             seajs.use('../static/test/seajsDemo.js');    
        });
    
    </script>
        
    
    </body>
    </html>
    
    seajsDemo.js
    
    define(function(require, exports, modeule){
    
        var seaUtil = require('./seaUtil');
    
        eBase = window.eBase = window.eBase || {}; 
        
        app = window.app = window.app || {};
    
        
         
    
    
        $.extend(eBase, {
            sayHello: function(){
                alert('hello , gray boy @');
            }
        });
    
        app.userManager = app.userManager || {};
    
        
    
    });
  • 相关阅读:
    SPOJ NSUBSTR
    一点对后缀自动机的理解 及模板
    HDU 1086 You can Solve a Geometry Problem too
    HDU2036 改革春风吹满地
    POJ 2318 TOYS
    [HNOI2008]玩具装箱TOY
    HDU 3507 Print Article
    洛谷 P1231 教辅的组成(网络最大流+拆点加源加汇)
    P3984 高兴的津津
    P2756 飞行员配对方案问题(网络流24题之一)
  • 原文地址:https://www.cnblogs.com/hengwu/p/9956916.html
Copyright © 2011-2022 走看看