简体   繁体   English

如何修复'ReferenceError:未定义matrixo'

[英]How to fix ' ReferenceError: matrixo is not defined'

i require matrixo function that in random.js, but in server.js but program cant find this function. 我需要在random.js中使用matrixo函数,但是在server.js中,但是程序找不到此函数。 Where do i need require random .js for fixing? 我在哪里需要使用随机.js进行修复?

server.js server.js

 var matrix = matrixo(40, 40);

let random = require('./modules/random.js');

random.js random.js

function matrixo(m) {
    var matrix = [];
    for (var i = 0; i < m; i++) {
        matrix.push([]);
        for (var j = 0; j < m; j++) {
            matrix[i][j] = Math.floor(Math.random() * 3);
        }
        for (var j = 0; j < m; j++) {
            matrix[i][j] = Math.floor(Math.random() * 4);
        }
        for (var j = 0; j < m + 3; j++) {
            matrix[i][j] = Math.floor(Math.random() * 5);
        }
        for (var j = 0; j < m; j++) {
            matrix[i][j] = Math.floor(Math.random() * 6);
        }
        for (var j = 0; j < m; j++) {
            matrix[i][j] = Math.floor(Math.random() * 7);
        }
    }
    return matrix;
}

module.exports = matrixo;

error - ReferenceError: matrixo is not defined 错误-ReferenceError:未定义matrixo

You need to assign the return value (which is the exported value) to the variable you are trying to use, and you need to do it before you use that variable. 您需要将返回值(这是导出的值)分配给您要使用的变量,并且需要在使用该变量之前进行此操作。

let matrixo = require('./modules/random.js');
var matrix = matrixo(40, 40);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM