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).]