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');
        };
    })

    完美,看看结果:

  • 相关阅读:
    c++重点笔记2
    c++学习笔记重点1
    创业思路(3) 传统行业与互联网思维
    创业思路(2) 社交
    创业思路(1)
    Asp.Net实现Http长连接推送
    又回来了
    2021.10.23软件更新公告
    2021.10.22软件更新公告
    SharePoint 2013 新特性 (三) 破改式 —— 设计管理器的使用 [2.HTML变身模板页]
  • 原文地址:https://www.cnblogs.com/kiscall/p/5280095.html
Copyright © 2011-2022 走看看