lukassz lukassz - 2 years ago 103
Javascript Question

NodeJS create object of function in module

I have file item.js

exports.itemParam = function(name, price, url, id){ = name;
this.price = price; = id;
this.url = url;

and in my www.js I require item.js

var item = require('../modules/item');

Which way can I create object of this function?

item.itemParam(a,b,c,k); // itemParam(a,b,c,k); ?

I have in www.js I execute this in

new itemParam(a,b,c,k);

Answer Source

Assuming you gonna keep your class definition, then this will work:

new item.itemParam(a,b,c,k);

itemParam function can't be used in www.js file without referring to the obejct that has one which is item.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download