我正在尝试在以下javascript文件中调用位于MathUtils对象内的randInt()函数。我想将参数从另一个javascript文件传递给randInt()并获取返回的结果。我没有通过正常的函数调用方法获得输出。请提出建议。
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.THREE = global.THREE || {})));
}(this, (function (exports) { 'use strict';
exports.Math=MathUtils;
var MathUtils = {
DEG2RAD: Math.PI / 180,
RAD2DEG: 180 / Math.PI,
// Random integer from <low, high> interval
randInt: function ( low, high ) {
return low + Math.floor( Math.random() * ( high - low + 1 ) );
},
// Random float from <low, high> interval
randFloat: function ( low, high ) {
return low + Math.random() * ( high - low );
}
}
})));
答案 0 :(得分:0)
看起来MathUtils
从未在JS文件中导出,即使在导出它时,对象也存在于THREE
命名空间内。
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.THREE = global.THREE || {})));
}(this, (function(exports) {
'use strict';
var MathUtils = {
DEG2RAD: Math.PI / 180,
RAD2DEG: 180 / Math.PI,
// Random integer from <low, high> interval
randInt: function(low, high) {
return low + Math.floor(Math.random() * (high - low + 1));
},
// Random float from <low, high> interval
randFloat: function(low, high) {
return low + Math.random() * (high - low);
}
}
// NOTE THIS LINE
exports.MathUtils = MathUtils
})));
// IN ANOTHER JS FILE:
console.log(THREE.MathUtils.randInt(1, 10))
&#13;