I also wondered how node re-point the "exports" reference, could you
explain it for me? Does not something like var module = {exports: {}}, if
change exports, why module.exports can't update?
在 2012年1月10日星期二UTC+8上午2时45分26秒,ryandesign写道:
>
>
> On Jan 9, 2012, at 07:34, mscdex wrote:
>
> >> BTW What is the main difference between exports and module.exports?
> >
> > exports === module.exports
>
> I had wondered this as well, and eventually reached this conclusion too:
> node must be doing the equivalent of "var exports = module.exports" to
> create the exports reference. It was very confusing to me to see some
> example code doing things with "exports.something" and other code doing
> things with "module.exports". I never saw any code doing anything with
> "module.exports.something" and I now assume this this would in fact work
> fine but nobody does it because it is seven characters shorter to type
> "exports" than "module.exports". But when overriding the entire exports
> object, just setting "exports" would not work, because that would re-point
> the "exports" reference instead of updating the real "module.exports"
> object. I never saw it explained in this way in any documentation, and it
> would have helped me understand quicker.
>
>
> > Setting `module.exports` would allow you to overwrite the default
> > `exports` object with whatever you want so that that would get
> > returned by require() instead of an object. This way you could do
>
>
--
--
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
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.