Closed Thread Icon

Preserved Topic: appendFunction() Pages that link to <a href="https://ozoneasylum.com/backlink?for=18041" title="Pages that link to Preserved Topic: appendFunction()" rel="nofollow" >Preserved Topic: appendFunction()\

 
Author Thread
lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-24-2001 13:08

Hi All!

Just thought that It would be a nice idea to expose this new function, and get your comments and improvments...

code:
<html>
<head>
<title>Function Append!</title>
</head>
<script language="JavaScript">
<!--
function appendFunction(from_fnc, to_fnc)
{
function parseFunctionName(fnc)
{
str = String(fnc);
return str.substr(str.indexOf("function ") + 8, str.indexOf("(") - 8 - (document.layers ? 1 : 0)); // 8 = length("function ");
}
fnc = new Function(
"function F_A() {\n" +
to_fnc + "\n" +
parseFunctionName(to_fnc)+ "();\n" +
"}\n" +
"function F_B() {\n" +
from_fnc + "\n" +
parseFunctionName(from_fnc)+ "();\n" +
"}\n" +
"F_A(); F_B();"
);
return fnc;
}
//-->
</script>

<body onload="alert('body loaded');">
<script language="JavaScript">
<!--
x = appendFunction(new Function("alert('a');"), new Function("alert('b');"));
alert('now appending all to the window.onload');
x = appendFunction(x, window.onload);
window.onload = x;
//-->
</script>
</body>
</html>



so...
x = appendFunction(new Function("alert('a');"), new Function("alert('b');"));
will append the first function to the second one, and they will be called as: function2(); function1();

-=lallous=-

[edit]fixed the example...[/edit]

[This message has been edited by lallous (edited 07-24-2001).]

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-26-2001 12:17

I feel I'm missing something here....
Is there is any simple way to append two functions?

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-26-2001 21:01

Well, not really. But just making a new function like

function twofunc()
{
funcone();
functwo();
}

does the trick fine. Nonetheless, it's an interesting peice of code.

« BackwardsOnwards »

Show Forum Drop Down Menu