I used to do the same thing only worse in my code, namely chaining extensions to exports...sometimes four or more deep. This is a habit I brought from statically typed OOP.
I don't do it anymore in JS, because it made refactoring a nightmare. The "problem" is...unless you have really good unit test coverage...the chain can easily be broken and you don't find out until way up the callstack. All it takes is the order changing or something inserted in between. That's the price of prototypes in a dynamic language...no compiler can tell if you really mean what you wrote. So now what I do is at most one layer of chaining...a common base and then every extension is self contained even though that means a little more typing. It's working for me. So I think what you have is fine, as long as you don't go to a third level. On Apr 27, 2012 9:54 PM, "akira" <[email protected]> wrote: > I am sorry if this is not node related, I just thought this might be a > good place to ask since a lot of module developers are on this list. > > Using this simple example, I would like to inherit a form > > exports.EmailForm = forms.Form.extend({ > email_address : forms.EmailField({required: true}) > }) > > exports.ExtendedEmailForm = exports.EmailForm.extend({ // <- Extending > EmailForm > subject : forms.CharField({maxLength: 100}) > , message : forms.CharField() > , sender : forms.EmailField({required: true}) > }) > > > Is this a misuse? It works, but normally one would do something like > this: > > var EmailForm = forms.Form.extend({ > email_address : forms.EmailField({required: true}) > }) > > > But I would like to export the simple EmailForm class for usage in > other modules too. Thanks > > -- > 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
