...

View Full Version : Just found something of interest....



ggallen
09-28-2004, 09:03 PM
I had posted a question about a year ago, wanting to know
how I could "transfer" a function from one program to a new
window with the document.write..

What I was trying to do was have one window create a new
window, functions and all, This new window could then be
saved to the hard drive for future running locally, which was
why I couldn't have the new window run the functions from
the original window (because after it's saved, only the new
window was saved).

Initially, I chose to duplicate the functions on in the originating
window, and the the other was just "data" to be written to the
new window as javascript functions (which took up some room).

But by accident, I found something today. that I haven't yet
fully explored that might solve my problem.

I had a function that computed a number, and returned that number.
so say:

function testfunct() {
var somenum=5;
return somenum;
}

OK...now for what amazed me.

put in this:

alert(testfunct);
So...

If I wanted to transplant a function I should in essence be able
to do:

var func1=testfunct;

then loop through func1, document writing each line.

Untested at present....has anyone done this?
I didn't have time to test the theory, and won't for a couple days

George

jamescover
09-29-2004, 03:35 AM
<script type="text/javascript">
<!--

function hello(message){
message = "hello";
}
var func1 = hello;
document.writeln(func1);

//-->
</script>


<script type="text/javascript">
<!--

function hello(message){
message = "hello";
}
var func1 = hello;
var newWin = window.open("","","");
newWin.document.open();
newWin.document.writeln(func1);
newWin.document.close();

//-->
</script>





-james



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum