node.js - TypeError: Object is not a function at Object.<anonymous> when constructing Javascript w new - Stack Ove

I've put together a little code in one file, which is below:var exports = Symphonize;function Symp

I've put together a little code in one file, which is below:

var exports = Symphonize;

function Symphonize(generation_specification) {
    this.generate_spec = function(){
        return generation_specification;
    }
}

When I start another JavaScript file in the same project and require the code like so:

var symphonize = require('../bin/symphonize');
var Symp = new symphonize({"test":"test1"});

It throws the error:

/Users/adron/Codez/symphonize/tests/symphonize.js:8

var Symp = new symphonize({"test":"test1"});

          ^ TypeError: object is not a function at Object.<anonymous>

Is there another way I should be constructing this? I just want the "symphonize" code to require a simple object (an object of configuration that will be JSON) before any functions on that code are called.

I've put together a little code in one file, which is below:

var exports = Symphonize;

function Symphonize(generation_specification) {
    this.generate_spec = function(){
        return generation_specification;
    }
}

When I start another JavaScript file in the same project and require the code like so:

var symphonize = require('../bin/symphonize');
var Symp = new symphonize({"test":"test1"});

It throws the error:

/Users/adron/Codez/symphonize/tests/symphonize.js:8

var Symp = new symphonize({"test":"test1"});

          ^ TypeError: object is not a function at Object.<anonymous>

Is there another way I should be constructing this? I just want the "symphonize" code to require a simple object (an object of configuration that will be JSON) before any functions on that code are called.

Share Improve this question asked Jan 3, 2014 at 17:24 AdronAdron 1,8663 gold badges21 silver badges41 bronze badges 2
  • 2 This should probably be moved to SO. – pllee Commented Jan 3, 2014 at 18:21
  • you're right. I've since stopped posting said items here. – Adron Commented Jan 7, 2014 at 23:35
Add a ment  | 

1 Answer 1

Reset to default 3

When setting the exports something you must do module.exports = Something. You should do something like :

module.exports = Symphonize;

If you had Symphonize as a property on the exports module.exports is not needed

exports.Symphonize = Symphonize;

Use it in a file.

var Symphonize = require('../bin/symphonize').Symphonize


Also var exports is kind of ambiguous statement in Node.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744037592a4547713.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信