Seiji Sam Lee | 6 Aug 2012 02:03
Picon

Looking for inspitarion ...

I keep on working in my node-based http server.

I am implementing sessions and, into this, installing code to be 
executed latter.

So I found a problem and need a bit of inspiration.

The fast way to explain the problem is ask: how can un-bind a variable?

well, I have a function:

function hello()
{
   $server.response.echo("Hi, world!");
   $server.end();
}

First time the page is requested, this function is installed, and second 
time this functions is executed (both with different response objects).

This doesn't work, but this does:

function hello($server)
{
   $server.response.echo("Hi, world!");
   $server.end();
}

Obviously the problem is the first version of 'hello' store the 
reference to $server, and the second no, because it is passed as 
(Continue reading)

Marak Squires | 6 Aug 2012 02:11
Picon
Gravatar

Re: Looking for inspitarion ...

Lot's of things going on here. It's hard to tell without more information, but it looks like you are playing fast and loose with scope. Generally, you shouldn't have to worry about "un-binding" things.


Can you post an entire runnable code example?

You might want to take a look at http://eloquentjavascript.net/ if you haven't already.



On Sun, Aug 5, 2012 at 5:03 PM, Seiji Sam Lee <seijisamlee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
I keep on working in my node-based http server.

I am implementing sessions and, into this, installing code to be executed latter.

So I found a problem and need a bit of inspiration.

The fast way to explain the problem is ask: how can un-bind a variable?

well, I have a function:

function hello()
{
  $server.response.echo("Hi, world!");
  $server.end();
}

First time the page is requested, this function is installed, and second time this functions is executed (both with different response objects).

This doesn't work, but this does:

function hello($server)
{
  $server.response.echo("Hi, world!");
  $server.end();
}

Obviously the problem is the first version of 'hello' store the reference to $server, and the second no, because it is passed as arguments, and bind is delayed.

Its possible to re-bind a code, that is, a function?


My first idea is implement $server (and other globals objects) as pure/complete proxies...

Thanks a lot: Fran.

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe <at> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Jake Verbaten | 6 Aug 2012 06:53
Picon
Gravatar

Re: Looking for inspitarion ...

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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Tim Caswell | 6 Aug 2012 17:13
Favicon
Gravatar

Re: Looking for inspitarion ...

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 <raynos2@...> 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@...
> To unsubscribe from this group, send email to
> nodejs+unsubscribe@...
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en


Gmane