By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,472 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,472 IT Pros & Developers. It's quick & easy.

Works in Firefox but not in IE6, any help appreciated....

P: n/a
Hi,

Thanks alot in advance. I got the following two functions in my
javascript which work fine in Firefox 1.5 but not in IE6. Can someone
please help? Thank you again.

--------------------snip---------------------
function myClass(){
var self = this;
}

function defaultAction(){
myClass.prototype.callOut = eval("function (){ " +
"alert('testing myClass'); " +
"}");
myObject = new myClass();
if( typeof(myObject) == 'undefined' ){
alert("myObject is not defined");
}
else if( typeof(myObject) == 'function' ){
alert("myObject is a function");
}
else{
alert("myObject is " + typeof(myObject));
}
for (property in myObject) {
alert("myObject has property - " + property);
}
myObject.callOut(); // Problem appear here. IE complains Object
Expected
}

Dec 28 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
DamonChong wrote:
Hi,

Thanks alot in advance. I got the following two functions in my
javascript which work fine in Firefox 1.5 but not in IE6. Can someone
please help? Thank you again.

A couple of tips when posting code: do not use tabs, use 2 or 4 spaces
for indentation and manually wrap code at about 70 characters to
prevent auto-wrapping. Also, reduce your test case to the minimum
required (though here that isn't much of an issue).

--------------------snip---------------------
function myClass(){
var self = this;
}

function defaultAction(){
myClass.prototype.callOut = eval("function (){ " +
"alert('testing myClass'); " +

Eval is almost never required:

myClass.prototype.callOut = function (){
alert('testing myClass');
}

"}"); myObject = new myClass();
if( typeof(myObject) == 'undefined' ){
alert("myObject is not defined");
}
else if( typeof(myObject) == 'function' ){
alert("myObject is a function");
}
else{
alert("myObject is " + typeof(myObject));
}
for (property in myObject) {
alert("myObject has property - " + property);
}
myObject.callOut(); // Problem appear here. IE complains Object
Expected
}


The following works fine in Firefox and IE 5.2:

function myClass(){
var self = this;
}
function defaultAction(){
myClass.prototype.callOut = function (){
alert('testing myClass');
}

myObject = new myClass();

alert("myObject is " + (typeof myObject) );

for (property in myObject) {
alert("myObject has property - " + property);
}

myObject.callOut();

}

defaultAction();

--
Rob
Dec 28 '05 #2

P: n/a
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?

Thank you again.

Dec 28 '05 #3

P: n/a
Damon Chong wrote:
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?
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


--
Rob
Dec 28 '05 #4

P: n/a
Thanks alot Rob, I tried it out on IE6 and it is working now. Your tips
were very helpful in solving my problem. Thanks again! =D

Dec 29 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.