我创建了一个简单的 Javascript 模块。我希望它可用于 CommonJS 实现、AMD 实现和全局 ()
这是我的类(class):
function Geolocation( callback ){
this._latitude = null;
this._longitude = null;
this._accuracy = null;
}
Geolocation.prototype = {
//prototype definitions in here
}
我想要实现的目标可能吗?彻底的谷歌搜索没有产生任何结果
最佳答案
(function (global, factory) {
if (typeof define === "function" && define.amd) define(factory); //AMD
else if (typeof module === "object") module.exports = factory(); //CommonJS
else global.Geolocation = factory(); // for example browser (global will be window object)
}(this, function () {
var Geolocation = function( callback ){
this._latitude = null;
this._longitude = null;
this._accuracy = null;
}
Geolocation.prototype = {
//prototype definitions in here
}
return Geolocation;
}));
关于javascript - 允许 Javascript 模块(类)与 CommonJS、AMD 或两者都不一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33522339/