[英]Node.js reference error : Classname is not defined
I have a file bloom.js which is as follows : 我有一个文件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;
In my main.js i am getting errors when doing this : 在我的main.js中,这样做时出现错误:
var Bloom = require("./bloom"); var Bloom = require(“ ./ bloom”); var bloom = new Bloom();
var bloom = new Bloom();
Error : 错误:
TypeError: Bloom is not a function
at Object.<anonymous> (J:\code\Main.js:114:13)
at Module._compile (module.js:409:26)
How can i resolve this error ? 我该如何解决此错误? I tried exporting module too but it didnt worked.
我也尝试导出模块,但没有成功。
// 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;
Then, in main.js: 然后,在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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.