Node.js引用错误:未定义Classname

时间:2016-05-11 23:17:57

标签: javascript node.js

我有一个文件bloom.js,如下所示:

jmeter -n -t test.jmx -Jtest.duration=3600 -Jtear.duration=20

在我的main.js中,我在执行此操作时遇到错误:

var Bloom = require(“./ bloom”); var bloom = new Bloom();

错误:

     function Bloom(k, m, n, hashFunction){

        if(!m)
            m = 1000

        this.m = m;

        if(!n)
            n = 100

        this.n = n;

        if(!k)
            k = Math.max(Math.round(m / n * Math.LN2), 1)

        this.k = k


        this.insert = function(string){

            for(var i = 0; i < this.k; i++){

                var index = parseInt(this.hashFunction(i + string), 16) % this.array.length

                this.array[index] = 1;
            }

            return true;
        }





    }
module.exports = Bloom;

如何解决此错误?我也试过导出模块,但它没有用。

1 个答案:

答案 0 :(得分:2)

// bloom.js
   function Bloom(k, m, n, hashFunction){

    if(!m)
        m = 1000

    this.m = m;

    if(!n)
        n = 100

    this.n = n;

    if(!k)
        k = Math.max(Math.round(m / n * Math.LN2), 1)

    this.k = k


    this.insert = function(string){

        for(var i = 0; i < this.k; i++){

            var index = parseInt(this.hashFunction(i + string), 16) % this.array.length

            this.array[index] = 1;
        }

        return true;
    }
}
module.exports = Bloom;

然后,在main.js中:

// NOTE! the variable name here is what matters, not what you defined in bloom.js
var Bloom = require("./bloom");
var bloom = new Bloom();