R
Rob Long
Hi there
Is there any way to access private variables directly from within a
priviliged function? I have a situation where the priviliged function's
execution context contains variables of the same name as the parent
context, but I want direct access to the parent context's variable.
E.g. I would like to be able to do this...
function Point()
{
var x = 0;
var y = 0;
this.setX(x)
{
// set private x with local x
}
this.setY(y)
{
// set private y with local y
}
}
I can obviously do this with
function Point()
{
var x = 0;
var y = 0;
this.setX(xLocal)
{
x = xLocal;
}
this.setY(yLocal)
{
y = yLocal;
}
}
But is there a way that avoids having to check for naming conflicts all
the time? I guess setX and setY will be assigned an execution context
and scope chain, but I need a way to access the scope chain one level
up, a bit like the "prototype" keyword can for "class" scope chains.
Problem is that "x" is being found in the first level so the next level
up is never checked. I'm no guru so I might be confusing things here,
but if I could do something *similar* to
this.setX(x)
{
prototype.x = x;
}
then I would be a very happy man... Cos in java I'm used to doing
void setX(int x)
{
this.x = x;
}
Thanks in advance!
Is there any way to access private variables directly from within a
priviliged function? I have a situation where the priviliged function's
execution context contains variables of the same name as the parent
context, but I want direct access to the parent context's variable.
E.g. I would like to be able to do this...
function Point()
{
var x = 0;
var y = 0;
this.setX(x)
{
// set private x with local x
}
this.setY(y)
{
// set private y with local y
}
}
I can obviously do this with
function Point()
{
var x = 0;
var y = 0;
this.setX(xLocal)
{
x = xLocal;
}
this.setY(yLocal)
{
y = yLocal;
}
}
But is there a way that avoids having to check for naming conflicts all
the time? I guess setX and setY will be assigned an execution context
and scope chain, but I need a way to access the scope chain one level
up, a bit like the "prototype" keyword can for "class" scope chains.
Problem is that "x" is being found in the first level so the next level
up is never checked. I'm no guru so I might be confusing things here,
but if I could do something *similar* to
this.setX(x)
{
prototype.x = x;
}
then I would be a very happy man... Cos in java I'm used to doing
void setX(int x)
{
this.x = x;
}
Thanks in advance!