zoukankan      html  css  js  c++  java
  • seaJS 简单上手

    seaJS和requireJS十分相似,只是其采用了CMD规范,如果写过nodeJS,一定很顺手。

    目录结构:

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <h2>SeaJS</h2>
    <script src="http://apps.bdimg.com/libs/seajs/2.3.0/sea.js"></script>
    <script type="text/javascript">
    seajs.config({
        base: './',
        alias: {
            jquery: 'conJS/jquery.js',
            ali: 'conJS/ali.js'
        }
    });
    seajs.use(['./index', './hello'],function(index, hello){
        hello.sayHello();
    });
    </script>
    </body>
    </html>

    引入sea.js,配置,使用。和requireJS多么相像,但是其使用的方法是use();

    其引入了index和hello模块,我们看下:

    hello.js

    define(function(require, exports) {
        var index = require('./index');
        var ali = require('ali');
        exports.sayHello = function(){
            ali.ali();
            index.log();
            console.log('Hello World!');
        };
    });

    通过require的范式加载模块,经典的AMD规范,注意index使用了相对路径,而ali没有使用相对路径,这是在前面配置好的。

    index.js

    define(function(require, exports) {
      exports.each = function (arr) {
        console.log('This is each Func.');
      };
    
      exports.log = function (str) {
        console.log('This is log Func.');
      };
    });

    ali.js

    define(function(require, exports) {
        exports.ali = function(){
            console.log('demo');
        };
    })

    完美,看看结果:

  • 相关阅读:
    codeforces 666C Codeword
    codeforces 156D Clues(prufer序列)
    codeforces 633E Startup Funding(浮点数处理)
    codeforces 932E Team Work(组合数学、dp)
    codeforces 1000F One Occurrence(线段树、想法)
    codeforces 812E Sagheer and Apple Tree(思维、nim博弈)
    写点文字
    00000
    省选前干些奇怪的事情
    PE415
  • 原文地址:https://www.cnblogs.com/kiscall/p/5280095.html
Copyright © 2011-2022 走看看