function (data) {
if (typeof data !== "string" || !data) {
return null;
}
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim(data);
// Attempt to parse using the native JSON parser first
if (window.JSON && window.JSON.parse) {
return window.JSON.parse(data);
}
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if (rvalidchars.test(data.replace(rvalidescape,"@").replace(rvalidtokens,"]").replace(rvalidbraces,""))) {
return (new Function("return " + data))();
}
jQuery.error("Invalid JSON: " + data);
}
我无法理解以下后备
return (new Function("return " + data))();
而且(这个不是在jQuery中)
return (eval('('+ data + ')')
我想知道这些事情
>这个解析后备如何工作?
>为什么eval不用于后备? (它不比新的Function()快)
最佳答案
原文链接:https://www.f2er.com/jquery/427977.html