问题描述
我知道如何用Javascript构建库,但是在jQuery中却大不相同。
// what I kNow
var Sambuca;
Sambuca = function(selector) {
var self = {};
self.selector = selector;
self.elements = (typeof selector === 'object') ?
new Array(self.selector) :
document.querySelectorAll(self.selector);
//Our functions will be put here
return self;
};
window.Sambuca = Sambuca;
window.$ === undefined && (window.$ = Sambuca)
// in jQuery
!function (e,t) {
"use strict";
"object" == typeof module && "object" == typeof module.exports ? module.exports = e.document ? t(e,!0) : function (e) {
if (!e.document) throw new Error("jquery module requires a window with a document");
return t(e)
} : t(e)
}("undefined" != typeof window ? window : this,function (C,e) {
"use strict";
});
答案 什么都找不到。 (thx stackoverflow )
在 ADJenks 的帮助下,我找到了很好的帮助,也许会对您有所帮助
链接在这里:https://gist.github.com/CrocoDillon/9990078
解决方法
他们正在尝试使其与模块加载程序兼容。 参见:https://github.com/umdjs/umd 将UMD与AMD和CommonJS进行比较。
我建议使用现代模块语法。就像这里:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
然后使用babeljs或其他编译器将其转换为与旧版浏览器更兼容的版本。