允许Javascript模块(类)与CommonJS、AMD或两者都不使用
Allowing a Javascript module (class) to be used with CommonJS, AMD or neither
我创建了一个简单的Javascript模块。我希望这可以用于CommonJS实现、AMD实现和全局()
这是我的课:
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;
}));
相关文章:
- 组合regex,同时匹配两者,而不是两者都匹配
- 如何更改其内容的 Iframe 高度(两者都来自同一域)
- 重用另一个模板中的 Mustache 模板,如果两者都在一个 html 文件中定义
- 我在表单页面上有一个弹出窗口以及一个隐藏元素,具体取决于用户输入.两者都使用 jquery
- 元素及其父元素指定了 ng-单击,两者都被调用
- 如何从.js文件访问asp标记中的js变量(两者都在同一页上执行)
- 节点-工厂或构造函数,或者两者都没有
- jQuery函数在$(window).resize()或$(document).ready()上执行,而不是两者都执行
- 执行单击或双击.不是两者都有
- 从js调用php函数-两者都在单独的文件中
- 允许Javascript模块(类)与CommonJS、AMD或两者都不使用
- 为什么两者都承诺's然后&catch回调被调用
- 确定属性在JavaScript中是getter还是setter(或两者都有)
- AngularJs或NodeJs或两者都有
- AngularJS和jQuery..两者都用有什么不对?
- Javascript: getElementById vs getElementsById(两者都在不同的页面上工作)
- 谷歌地图标记或地图将显示,但不是两者都显示
- 是否有理由使用array.forEach()而不是for..在ES6中,两者都可以使用
- 我想在第一个选择的基础上填充第二个选择表单.两者都在从sql数据库中检索它们的元素
- jQuery1.9将html附加到页面中,然后是一个脚本,两者都依赖于文档准备