2009/11/20 David <[email protected]>

>
> Hi, Ondřej. Thanks for the speedy reply. I think I am still missing
> something, however. Here's the sample code I'm playing with:
>
> ==
>
> which outputs:
>
> ==
> doggie in other scope = undefined
> doggie in global = undefined
> ==
>
> Do you have any insights into what I might be doing wrong?
>
>

Hi David,

running function in different scopes only changes the "this" value in the
function. In JS world, you would similarly do:

var myFunc = function() {}
myFunc();
myFunc.call(someOtherContextObject);

However, variables declared in function with "var" keyword are always local
to the function - and global if executed outside any function declaration.

In other words: if you want to use "var x = ..." and be able to choose where
will the "x" property be created, you are out of luck (imho). But if you
change your function to "this.x = ...", you can switch the context object as
necessary.


Ondrej




> Thanks,
> David
>
>
>
> On Nov 20, 2:53 pm, Ondřej Žára <[email protected]> wrote:
> > Hi David,
> >
> > I believe that "wrapping" is actually the right way to go.
> >
> > Prepend your string with "function() {" and append "}"; compile, run and
> > convert the result to function. v8::Handle<v8::Function> has then the
> Call()
> > method, in which the first argument is your scope object....
> >
> > Ondrej
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to