By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,565 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Getting a variable reference, or accessing call objects?

P: n/a
Does anyone know....

In JavaScript, is there any way to get a reference to a string variable
(not an object), like Perl's "\" operator? I want to be able to compare
two such references and know if they point to the same string variable.

Alternately, is there a way to access the call object in a function, i.e.
the object that function-local variables are a part of? How about the
chain of call objects, e.g. if function a() calls function b(), then from
within b() is it possible to get function a()'s call object? I don't
think Function.caller does this, and that's deprecated anyway.

The problem is this: I have an app that reads and modifies JS code in Web
pages. In the following code I need to know whether the "src=bar" line
operates on the global window.src, or on the local "src" variable in f(),
when the "var src" line may or may not be there. Is there any way to do
this, short of parsing the function and keeping track of all "var"
declarations?

src= foo ;
function f() {
src= bar ;
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> In JavaScript, is there any way to get a reference to a string variable
(not an object), like Perl's "\" operator? I want to be able to compare
two such references and know if they point to the same string variable.
In JavaScript, all strings are immutable, and all strings containing the
same character sequence are equal. Your question does not make sense in
JavaScript/

The problem is this: I have an app that reads and modifies JS code in
Web pages. In the following code I need to know whether the "src=bar"
line operates on the global window.src, or on the local "src" variable
in f(), when the "var src" line may or may not be there. Is there any
way to do this, short of parsing the function and keeping track of all
"var" declarations?

src= foo ;
function f() {
src= bar ;
.
.
.
var src ; // may or may not be here
}


This seems like a very dangerous pattern. Why are you modifying JS code?
Jul 23 '05 #2

P: n/a
On Sun, 27 Feb 2005, Douglas Crockford wrote:

DC> > In JavaScript, is there any way to get a reference to a string variable
DC> > (not an object), like Perl's "\" operator? I want to be able to compare
DC> > two such references and know if they point to the same string variable.
DC>
DC> In JavaScript, all strings are immutable, and all strings containing
DC> the same character sequence are equal. Your question does not make
DC> sense in JavaScript/

It would be one possible solution to my problem.
DC> > The problem is this: I have an app that reads and modifies JS code in Web
DC> > pages. In the following code I need to know whether the "src=bar" line
DC> > operates on the global window.src, or on the local "src" variable in f(),
DC> > when the "var src" line may or may not be there. Is there any way to do
DC> > this, short of parsing the function and keeping track of all "var"
DC> > declarations?
DC> >
DC> > src= foo ;
DC> > function f() {
DC> > src= bar ;
DC> > .
DC> > .
DC> > .
DC> > var src ; // may or may not be here
DC> > }
DC>
DC> This seems like a very dangerous pattern. Why are you modifying JS code?

To make HTML and other resources retrieved through my program retrieve all
of their respective referred-to resources through the same program. What
is dangerous about it? What do you mean by "pattern" here?
.................................................. ...........................
James Marshall ja***@jmarshall.com Berkeley, CA @}-'-,--
"Teach people what you know."
.................................................. ...........................
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.