I would say you don't need this. Just create a function with a capitalized first letter. That's your class. Instantiate with `new`. Assign stuff to the prototype. Use `util.inherits` (or the `inherits` module if you prefer) to do inheritance, if you need to.
It's much better to write idiomatic JavaScript rather than twist JavaScript to look like some other language. Yes, of course you *can* do it, and you might learn something from it, but it's not actually a good idea to use such things in real life. I'd suggest writing a few more OOP helper wrapper doohickeys. In fact, continue writing them until you see through the matrix of OOP to the true nature of prototypes, and deeply grok that it's all just the same thing, so you may as well use the one that's the most optimized by the VM, and the most readily understandable to other users of the language. That is, if you seek enlightenment. If you just wanna get something done, use plain old boring JavaScript style OOP. On Wed, Oct 31, 2012 at 3:37 PM, Fredrik O <[email protected]> wrote: > Hi everyone, > > I have just wrote a simple lightweight OOP helper and want your thoughts > about it, the implementation "Class" is only 15 lines of code, but I have > included some tests, to show how it works. Any feedback is welcome. I am no > JavaScript expert, but if I have not done anything wrong should always the > generated class be 100% compatible with normal JavaScript prototype > inheritance and indeed be very fast. It allows a user write somewhat more > simple code. > > See gist: https://gist.github.com/3990372 > > What are your thoughts? Both negative and positive. And please, one comment > is better than no one, so please comment if you read through the gist. > > Thanks in advance! > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
