Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How do I set what "this" refers to?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Glidos  
View profile  
 More options May 2 2012, 11:58 am
From: Glidos <goo...@glidos.net>
Date: Wed, 2 May 2012 08:58:33 -0700 (PDT)
Local: Wed, May 2 2012 11:58 am
Subject: How do I set what "this" refers to?
I need to run scripts that use a convention of "this" refering to a
specific, otherwise-unnamed object. Is there a way to make v8 handle
that convention?

So far the only work-around I can think of is to provide the global
template with an explicit property to refer to the object
(implicitThisObj say). Then I'd alter the incoming  <script-text> to
be

implicitThisObj.tempFunc = function() { <script-text> };
implicitThisObj.tempFunc();

but that's a bit messy. Anyone know a better way?

Cheers,
   Paul.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Rossberg  
View profile  
 More options May 2 2012, 12:07 pm
From: Andreas Rossberg <rossb...@google.com>
Date: Wed, 2 May 2012 18:07:52 +0200
Local: Wed, May 2 2012 12:07 pm
Subject: Re: [v8-users] How do I set what "this" refers to?
On 2 May 2012 17:58, Glidos <goo...@glidos.net> wrote:

> I need to run scripts that use a convention of "this" refering to a
> specific, otherwise-unnamed object. Is there a way to make v8 handle
> that convention?

> So far the only work-around I can think of is to provide the global
> template with an explicit property to refer to the object
> (implicitThisObj say). Then I'd alter the incoming  <script-text> to
> be

> implicitThisObj.tempFunc = function() { <script-text> };
> implicitThisObj.tempFunc();

> but that's a bit messy. Anyone know a better way?

Rewrite to:

(function() { <script-text> }).call(implicitThisObj)

That's the easiest way. The global object is quite special, and cannot
just be replaced it with a random object.

/Andreas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephan Beal  
View profile  
 More options May 2 2012, 1:07 pm
From: Stephan Beal <sgb...@googlemail.com>
Date: Wed, 2 May 2012 19:07:13 +0200
Local: Wed, May 2 2012 1:07 pm
Subject: Re: [v8-users] How do I set what "this" refers to?

On Wed, May 2, 2012 at 6:07 PM, Andreas Rossberg <rossb...@google.com>wrote:

> (function() { <script-text> }).call(implicitThisObj)

See also Function.apply(). The only difference between apply() and call()
is how the 2nd+ argument(s) are passed to it:

myFunc.call( myObj, 1, 2 );
===
myFunc.apply( myObj, [1, 2] );

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glidos  
View profile  
 More options May 2 2012, 6:13 pm
From: Glidos <goo...@glidos.net>
Date: Wed, 2 May 2012 15:13:17 -0700 (PDT)
Local: Wed, May 2 2012 6:13 pm
Subject: Re: How do I set what "this" refers to?
Thanks. Both apply and call are improvements over my attempt, but
maybe I don't need any tricks:
if I just get v8 to execute <script-text> directly, will "this" refer
to the global object?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ruben Rodriguez  
View profile  
 More options May 2 2012, 6:30 pm
From: Ruben Rodriguez <rubentb...@gmail.com>
Date: Wed, 2 May 2012 17:30:20 -0500
Local: Wed, May 2 2012 6:30 pm
Subject: Re: [v8-users] Re: How do I set what "this" refers to?

Yes. The global object of the context within which you execute the script.

from my hacked android ;)
On May 2, 2012 5:13 PM, "Glidos" <goo...@glidos.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glidos  
View profile  
 More options May 9 2012, 10:02 am
From: Glidos <goo...@glidos.net>
Date: Wed, 9 May 2012 07:02:56 -0700 (PDT)
Local: Wed, May 9 2012 10:02 am
Subject: Re: How do I set what "this" refers to?
Brilliant. That all works now. Thanks for the help.

On May 2, 11:30 pm, Ruben Rodriguez <rubentb...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »