// 该写法为了满足多条件下的 CommonJs,Node.js, window,layui
(function (name, factory) {
// 检测上下文是否为AMD或者CMD
var hasDefine = typeof define === "function",
// 检查上下文环境是否为Node
hasExports = typeof module !== 'undefined' && module.exports,
hasLayui = this.layui && layui.define;
if (hasDefine) {
// AMD 环境或者 CMD环境
define(factory);
} else if (hasExports) {
// 定义为普通的Node模块
module.exports = factory();
} else if (hasLayui) {
// 是否为layui模块
layui.define(['jquery'], function (exports) {
exports('com', factory());
});
} else {
// window对象
this[name] = factory();
}
}
)('com', function () {
"use strict";
var Com = function Com(params) {
};
Com.prototype.info = function () {
const info = {
version: 'v-1.0.1',
description: 'Com只是一个测试兼容多种规范的样例!',
author: 'Mc.Sumi',
date: '2018-11-01 15:00:00'
}
console.log(`当前Com的详细介绍:\n ${info} `);
return info;
}
return new Com(); // 返回构造
});
该写法为了满足多条件下的 CommonJs,Node.js, window,layui
最新推荐文章于 2022-08-01 10:47:55 发布