J
Julian Turner
Randy Webb wrote:
[snip]
I see the point.
I suppose the question then is in what circumstances is myVar being
local a problem that does not have a work-around?
It's reputation is definitely not helped when it is misused.
For a particularly egregious example of misuse, and for fun only, I use
eval for my own libraries to nest my modules (with a downward only
dependency)
E.g.
module1 - core functions
module2 - Array, String - uses module1
module3 - HTML - uses modules 2 and 2
function module1()
{
this.closure = function(source)
{
var retVal;
eval(source);
return retVal;
};
function module1Function() {
alert("hello from module1");
}
this.module1Function = module1Function;
}
function module2()
{
this.closure = function(source)
{
var retVal;
eval(source);
return retVal;
};
function module2Function() {
module1Function(); // Will be in scope chain
}
this.module2Function = module2Function;
}
function module3()
{
function module3Function() {
module2Function(); // Will be in scope chain
}
this.module3Function = module3Function
}
module1 = new module1();
module2 = module1.closure(module2.toString() + " retVal = new
module2()");
module3 = module2.closure(module3.toString() + "retVal = new
module3()");
module3.module3Function();
The real version is a little more friendly, but that hopefully
illustrates the insane gist of it.
I know, I know, closures, scopes and scope chain look-ups lead to poor
memory and speed performance, but in practice I am not noticing much of
a performance hit for modest applications.
I am not sure I follow this.
[snip]
Anticipation is good.
[snip]
It is also patented!
<URL:http://patft.uspto.gov/netacgi/nph-...6,941,562.PN.&OS=PN/6,941,562&RS=PN/6,941,562>
Regards
Julian
[snip]
[/snip]You load the HTML, insert it in a container, then want to execute the
script block. You run a function that evals the script contents. myVar
then becomes local to the function.
I see the point.
I suppose the question then is in what circumstances is myVar being
local a problem that does not have a work-around?
The biggest thing? I hate eval
It's reputation is definitely not helped when it is misused.
For a particularly egregious example of misuse, and for fun only, I use
eval for my own libraries to nest my modules (with a downward only
dependency)
E.g.
module1 - core functions
module2 - Array, String - uses module1
module3 - HTML - uses modules 2 and 2
function module1()
{
this.closure = function(source)
{
var retVal;
eval(source);
return retVal;
};
function module1Function() {
alert("hello from module1");
}
this.module1Function = module1Function;
}
function module2()
{
this.closure = function(source)
{
var retVal;
eval(source);
return retVal;
};
function module2Function() {
module1Function(); // Will be in scope chain
}
this.module2Function = module2Function;
}
function module3()
{
function module3Function() {
module2Function(); // Will be in scope chain
}
this.module3Function = module3Function
}
module1 = new module1();
module2 = module1.closure(module2.toString() + " retVal = new
module2()");
module3 = module2.closure(module3.toString() + "retVal = new
module3()");
module3.module3Function();
The real version is a little more friendly, but that hopefully
illustrates the insane gist of it.
I know, I know, closures, scopes and scope chain look-ups lead to poor
memory and speed performance, but in practice I am not noticing much of
a performance hit for modest applications.
Second scenario is one that I can not come up with a reasonable reason
to ever do but it involves a script block that traverses the tree going
upwards using parentNode to get to an element. As I say, that is a
perverse scenario that if I ever saw actual code that did it I would
probably wonder what insane asylum the author was a patient at.
I am not sure I follow this.
[snip]
[/snip]Close. Three years ago you didn't see questions in this group with
regards to XMLHttpRequest and/or AJAX very often. Now, you see a
kazillion of them. The next phase of that, to me, is going to be script
issues and it is already happening where people are asking "How do I
make my scripts execute when loaded with AJAX" and I am simply trying to
be ahead of it and come up with an answer before the onslaught happens.
Anticipation is good.
[snip]
[/snip]The approach I use, and prefer, for loading data is .js files and
loading them on the fly. The back end still has to be set up to create
those .js files and the main page is set up to handle it. I just find
the .js files simpler and more reliable than AJAX is all.
It is also patented!
<URL:http://patft.uspto.gov/netacgi/nph-...6,941,562.PN.&OS=PN/6,941,562&RS=PN/6,941,562>
Regards
Julian