tag:blogger.com,1999:blog-5349283373421007883.post3665443579904081809..comments2022-02-09T08:24:15.974-05:00Comments on Recoding: Exporting a JavaScript "object" in nodeAnonymoushttp://www.blogger.com/profile/04878499246877326740noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-5349283373421007883.post-42887936612517431822013-01-08T02:00:54.331-05:002013-01-08T02:00:54.331-05:00I'd like to offer up an alternative: Instead o...I'd like to offer up an alternative: Instead of using constructor functions (pseudo-classical style), use a more purely prototypal style. Set module.exports to an object, which can then be used as the prototype of new objects via Object.create(). For initialization, my preference is to include an "init" function on the prototype object, though a factory pattern or simply setting properties could be used as well.<br /><br />Check out https://github.com/ryankinal/node-content/blob/master/content/article.js for the prototype code, and https://github.com/ryankinal/node-content/blob/master/content-db/content-db.js for the "instantiation" code.Ryan Kinalhttps://github.com/ryankinalnoreply@blogger.com