Node.js modules vs Objects

I have been playing around with node.js, and coming from a Java background, I am struggling to differentiate between modules and the typical concept of objects in JavaScript. When implementing a modules, I am currently doing it this way: // someModule.js var privateVariable; this.sampleFunction = function() { // ... } Now, the way I am using this module in another place is: var moduleName = require('./someModule'); var foo = moduleName.sampleFunction(); I don't know if this is the right way to do modular development in node.js - because I realized I am not actually using objects, like using new() - which I would need to do when I want to have collections etc. What is the right way to proceed here if I want a collection of person objects - how will my module and it's definition look like?
For general background on your question you might find JavaScript: The Good Parts by Douglas Crockford a helpful read. It provides a clear and concise (the whole book is only 176 pages--a rarity) explanation of how JavaScript differs from "classical" (as the author refers to them) languages.

以上就是Node.js modules vs Objects的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏