Expand Minimize
This topic has not yet been rated - Rate this topic

Indirect' eval' Function Calls Behave Differently in Windows Internet Explorer 9

Calling eval methods indirectly (that is, other than by the explicit use of its name) inside a function produces different results in Windows Internet Explorer 9 than it does in Windows Internet Explorer 8.

In all compatibility modes in Internet Explorer 8 and IE5 (Quirks) mode, IE7 Standards mode, and IE8 Standards mode in Internet Explorer 9, the string passed to the indirect eval is evaluated in the local function scope. In IE9 Standards mode in Internet Explorer 9, it is evaluated in the global scope as per the ECMAScript Language Specification, 5th edition.

Symptom

The eval function behaves as expected in IE5 mode, IE7 mode, and IE8 mode but returns "undefined" in IE9 mode.

Resolution

Call the eval method directly.

Examples

In the following example, the eval function has been called indirectly by assigning it to a variable and calling the variable as if it were eval.


function test() {
   var dateFn = "Date(1971,3,8)";
   var myDate;
   var indirectEval = eval;
   indirectEval("myDate = new " + dateFn + ";");
   document.write(myDate);
}
test();

This sample will return "Thu Apr 8 00:00:00 PDT 1971" in all document modes in Internet Explorer 8, and IE5 mode, IE7 mode, and IE8 mode in Internet Explorer 9. However in IE9 mode in Internet Explorer 9, this would print "undefined".

Related Topics

 

 

Build date: 9/28/2012

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.