Damon Chong wrote:[color=blue]
> Thanks alot Rob. The problem is I need the eval() method as I don't
> know what is the functions that might be created dynamically during
> runtime. In this case, I simply coded the eval("function().....") but
> in future it could be like below,
>
> myClass.prototype.callOut = eval(strval); // where strval is a String
> variable
>
> I guess it is abit convulated but surprising it works fine in Firefox.
> Is this way of dynamically creating a function supported in IE 5 and
> above?[/color]
I can't comment on that in general, I'm testing on Mac OS at the
moment so IE 5.2 is all I can do.
What you are trying to do does not appear to be much different from
using JSON, here is another alternative (tested in Safari, Firefox &
IE 5.2):
<script type="text/javascript">
var myObject;
var funcBody = "alert('testing myClass')"
function myClass(){
var self = this;
}
function defaultAction()
{
myClass.prototype.callOut = new Function(funcBody);
myObject = new myClass();
for (property in myObject) {
alert("myObject has property - " + property);
}
myObject.callOut();
}
defaultAction();
</script>
There is a (rather long) discussion on eval and JSON here, but Jim
Ley's resonponse seems pretty good:
<URL:
http://groups.google.com/group/comp....70fb75d49557a7[color=blue]
>[/color]
--
Rob