On May 19, 2014, at 8:36 AM, Michael DeMond <[email protected]> wrote:
> My problem had to do with how I was packaging my code for my Node.js
> application. Essentially, I was creating a single "application.js" file, but
> the contents would be:
>
> <entry.js>
> <dependency.js>
>
> entry.js was referencing elements in dependency.js, but since dependency.js
> was being emitted *after* entry.js, I was getting a ReferenceError at
> runtime. By putting my entry.js in a setTimeout (with 0ms), I was able to
> work around this problem. setTimeout has always seemed like a hack to me, so
> I try to avoid it at all costs, but here it seems like a good use of it.
>
Michael, if entry.js has a dependency on dependency.js, then I'd suggest
require()'ing dependency.js in entry.js (require caching should, in most cases,
avoid reloading dependency.js even if it is multiply required). Or load
dependency.js first. I think you may be using "emitted" wrongly, above, unless
there is actually some event being emitted by dependency.js which is listened
to in entry.js.
I think you are right in your wariness of using a setTimeout hack. I'd suggest
not using it here as well.
--ravi
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/010C8A32-ABA9-4BDF-AA3D-DF9DCE2B4EC6%40g8o.net.
For more options, visit https://groups.google.com/d/optout.