Closure variables are bound lexically to functions.

    // Create a local variable named "name" that points to the
primitive string "Tim"
    var name = "Tim"

    // Create a function who's [scope] inherits from the current scope.
    function printName() {
      console.log(name);
    }

    // Call the function executing the closure inside of it, it's able
to get at "name" from it's inherited lexical scope
    printName();

    // Point the "name" variable to a new value "Bob"
    name = "Bob";

    // Call the function again to see that indeed the closure is
sharing the same "name" variable.
    printName();


Of course in async systems where callbacks abound, changing global
state to configure functions is dangerous.  In your example, the
response object is unique per request, but the server is shared.  It's
not a good idea to store the request on the server as a property
because there can be many concurrent requests going on at once in the
same server.


On Sun, Aug 5, 2012 at 11:53 PM, Jake Verbaten <rayn...@gmail.com> wrote:
>> My first idea is implement $server (and other globals objects) as
>> pure/complete proxies...
>
> Your code structure / design will be a lot better if you stick to a strict
> no globals policy
>
> --
> 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 nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> 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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to