seiji, what are you trying to do?

you can nearly do whatever you need to do using closures (passing
functions to functions), rather than with eval.

the cases that need eval are really rather rare, like to be able to
send a function to another process, and then run it there, or to build
a module system.

if you need to pass some code into something, you can do it like this:

function size () {
  return {WIDTH: 700, HEIGHT: 300}
}

function doSomeThingWithSize (sizeCreator) {
  var size = sizeCreator()
  console.log(size)
}

doSomeThingWithSize(size)

//although, I'm really just guessing at what you may be attempting to do.



On Wed, Aug 1, 2012 at 2:46 AM, Tim Caswell <[email protected]> wrote:
> On Mon, Jul 30, 2012 at 6:36 PM, Seiji Sam Lee <[email protected]> wrote:
>> Thanks Tim, but it's more complicated than this.
>>
>> It would be the sum of two errors, maybe a lack in runIn{New,This}Context
>> and sure a lack in my mind!
>>
>> But the reality is that this code doesn't work for me (into a
>> runInNewContext):
>>
>> var WIDTH =750;
>> var HEIGHT=300;
>>
>> console.log(Util.inspect(this));
>
> I don't understand what you want to happen here.  You create two local
> variables WIDTH and HEIGHT, and then log the "this" context.  Local
> variables don't go on "this" (except for the global case in browsers).
>>
>> //Util is from require("Utils");
>>
>> it prints {} when executed into a runInNewContext
>>
>> Where are the objected stored?
>>
>> I have discarded a fail in my code (=owned candidate?)
>>
>> El 28/07/12 21:10, Tim Caswell escribió:
>>
>>> To be "exactly" like eval, use eval.  What property about eval do you
>>> need?  "this" is set by how you call a function, it can change on
>>> every call (except for bound functions).  Closure scope in eval is
>>> probably what you're talking about.  I generally use runInNewContext
>>> and pass in all the variables manually I needed from the closure.
>>>
>>> On Sat, Jul 28, 2012 at 2:44 AM, Seiji Sam Lee <[email protected]>
>>> wrote:
>>>>
>>>> I am working in a project that implements a basic plug-in engine.
>>>>
>>>> I tried to use runInNewContext(...) and the rest of similar
>>>> implementations
>>>> in VM module; but finally only was able to do using eval.
>>>>
>>>> My fault is I don't understand well contexts, 'this' keyword and so, but
>>>> I
>>>> could improve my knowledge if somebody ask this question:
>>>>
>>>> How can emulate 'exactly' eval using only methods from VM module?
>>>>
>>>> volunteers?
>>>>
>>>>
>>>>
>>>> Thank you in advance, I had been working for 10 hours straight and I am
>>>> not
>>>> able to think with properly XD
>>>>
>>>> --
>>>> 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
>
> --
> 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

Reply via email to