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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -