lukassz lukassz - 1 year ago 58
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);


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.