节点对象模块返回对象

时间:2015-05-26 17:04:39

标签: object module undefined

是否可以将Node对象从文件返回到另一个文件?

前:

file_1

myObject = function(x){
    this.x = x
    this.change = function(){
        return myObject("new_value");
    }
}
module.exports = myObject;

file_2

F1 = require('file_2');
f1 = new F1("some_value");
new = f1.change();

在我的代码中, new 现在有" undefined"。有没有办法返回新对象?

1 个答案:

答案 0 :(得分:0)

file_1应为:

myObject = function(x){
    this.x = x
    this.change = function(){
        return myObject("new_value");
    }
}
module.exports = myObject;