"Ken Kast" <ke*@NOSPAMkenkast.com> writes:
....
function doSomething () {
var obj = new Obj();
obj.foo = bar;
doSomethingElse(obj);
}
In function doSomethingElse I want to create the following line of DHTML
<div onClick="obj.foo(); return true;">
What I want is for onClick to be defined to be the execution of the foo
method of obj.
Then this won't work.
At this point of the execution, the only reference to the object is
the first parameter of the doSomethingElse function.
What you want to write is a way to reference that value from the global
scope (where the intrinsic event handler is executed).
To do that, you must make a globally available reference to the object.
Say:
window.xyzzy = arg1; // or whatever the parameter is called
document.writeln ("<div onclick='window.xyzzy(); " +
"return true;'>");
I tried document.writeln ("<div onClick='" + obj.foo + "(); return
true;'>");
What I get is the source code for bar stuck into the middle of the string.
Yes. I am not sure you realize that you are building syntax here. There
is no way for the syntax to carry an actual reference to the object. At
best it can contain syntax that evaluates to such a reference, but only
if such a reference is available at all in the scope where the code is
executed.
So how do I get just the name of the function bar in the string?
You don't want the name (it's "bar"). You want a Javascript expression
(syntax) that, when evaluated as an intrinsic event handler, evaluates
to a reference to the existing object.
Or ultimately, how do I get the handler to be bar in the DHTML?
Make a global reference with either a fixed or a computed name,
and then use that in the syntax you write.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'