Node.js引用错误:未定义类名
Node.js reference error : Classname is not defined
我有一个文件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中,我在执行以下操作时出错:
var Bloom=require("./Bloom");var bloom=new bloom()
错误:
TypeError: Bloom is not a function
at Object.<anonymous> (J:'code'Main.js:114:13)
at Module._compile (module.js:409:26)
如何解决此错误?我也试过导出模块,但没有成功。
// 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();
相关文章:
- chrome.storage.sync未定义错误
- 对象为null或IE9中存在未定义错误
- 已定义变量出现未定义错误
- 'define' 在 RequireJS 和 Webapp Yo 生成器上未定义错误
- onreadystatechange未定义错误
- 在CoffeeScript文件上运行Jasmine测试时,对象未定义错误
- 如何修复JSlint报告的“foo未定义”错误
- 无法仅在活动服务器上读取未定义错误的属性“top”
- 主干无法读取属性'属性'主干视图中的未定义错误
- 如何克服javascript中的未定义错误
- require未定义错误
- 单击链接时出现函数未定义错误
- 函数为未定义错误
- 主干未定义错误
- 使用Javascript打印HTML:未定义错误
- 避免“无法读取”属性'获取'的未定义错误
- 未捕获类型错误的coffescription:无法读取属性'offsetWidth'的未定义错误
- ajax上get函数内部的未定义错误
- Javascript变量未定义错误
- AngularJS指令作用域未解析(“属性名称未定义”错误)