D
Darko
Hello,
I have this particular problem with eval() when using Microsoft
Internet Explorer, when trying to define an event handler. This is the
code:
function BigObject()
{
this.items = new Array();
this.values = new Array();
this.addItem = function( item )
{
this.items[this.items.length] = item;
}
this.makeHandlers()
{
var i, length = this.items.length;
for ( i = 0; i < length; i++ )
this.items.onclick = function()
{ alert( this.values ); };
}
}
However, this last code (makeHandlers() method) doesn't work since the
expression "this.values" automatically belongs to this new
anonymous function, and therefore isn't valid (since the new anonymous
function(s) don't have the "values" attribute. So I tried the
following:
this.items.onclick = eval( "function() { alert( " +
this.values + "); }" );
and it worked! ... in Firefox only Internet explorer returns
"undefined" for eval( "function() { /* whatever */ ); } " ), for the
same things Firefox perfectly understands, and if I try to make it a
handler, an exception is fired in IE. What do I do? Did I come to the
right conclusion with IE or am I making a banal mistake? Do I need to
find another way of solving this or is there a fix to this solution?
Thank you,
Darko
I have this particular problem with eval() when using Microsoft
Internet Explorer, when trying to define an event handler. This is the
code:
function BigObject()
{
this.items = new Array();
this.values = new Array();
this.addItem = function( item )
{
this.items[this.items.length] = item;
}
this.makeHandlers()
{
var i, length = this.items.length;
for ( i = 0; i < length; i++ )
this.items.onclick = function()
{ alert( this.values ); };
}
}
However, this last code (makeHandlers() method) doesn't work since the
expression "this.values" automatically belongs to this new
anonymous function, and therefore isn't valid (since the new anonymous
function(s) don't have the "values" attribute. So I tried the
following:
this.items.onclick = eval( "function() { alert( " +
this.values + "); }" );
and it worked! ... in Firefox only Internet explorer returns
"undefined" for eval( "function() { /* whatever */ ); } " ), for the
same things Firefox perfectly understands, and if I try to make it a
handler, an exception is fired in IE. What do I do? Did I come to the
right conclusion with IE or am I making a banal mistake? Do I need to
find another way of solving this or is there a fix to this solution?
Thank you,
Darko