javascript - Node.js modules vs Objects -
i have been playing around node.js, , coming java background, struggling differentiate between modules , typical concept of objects in javascript.
when implementing modules, doing way:
// somemodule.js var privatevariable; this.samplefunction = function() { // ... }
now, way using module in place is:
var modulename = require('./somemodule'); var foo = modulename.samplefunction();
i don't know if right way modular development in node.js - because realized not using objects, using new() - need when want have collections etc. right way proceed here if want collection of person objects - how module , it's definition like?
// somemodule.js var privatevariable; this.person = function(firstname, lastname) { this.firstname = '...'; }
and then:
var modulename = require('./somemodule'); var foo = new modulename.person('foo', 'bar');
Comments
Post a Comment