Use the new Function () for syntax checking
The eval () method is not available for random use, and using the eval () method when it is not appropriate may cause the entire program to be problematic;
and the new Function () is not that big a problem. Although the new function () in any case, the constructed function works directly under the global scope, but only for syntax checking, it will not produce unexpected results because of the scope problem, as long as you do not directly call the new function constructed through it.
Increase "0," before the parameters that are accepted by eval ()
In fact, this is because there is a bug in IE. For some reason, if you want to dynamically construct a function in IE by calling Eval ().
For example:
Eval (' (function () {/* * code here/}) ');
The return obtained in IE will be undefined, while the other browsers will correctly return the reference to the newly constructed function.
The simplest and most effective solution is to add "0" to the front so that it is compatible in all major browsers.
For example:
Eval (' 0,function () {/* code here/} ');
Note: In IE9 's chakra engine, this problem has been solved.
Using the Concat method of an array object to produce a new array
You can use the form "[].concat (O)") to convert a single object parameter to an array containing only one element for processing.
For example:
Copy Code code as follows:
var arr1 = [1,2];
var arr2 = [3,4];
var arr3 = Arr1.concat (ARR2);
alert (arr3.length);
Another way is: if (!) ( o instanceof Array)) o = [O];
Compared with the IsArray in ECMAScript 5, it is not rigorous enough.
User reply:
1.eval really cannot be used indiscriminately;
2. In IE eval, my solution is to return in the execution function body;
3.array.prototype.concat.apply ([1,2,3],[4,5,6]);