标签:eva color log 参考 ajax net rip result 服务
var bar = ‘bar‘; var foobar = eval(‘"foo" + bar‘); alert(foobar);
eval评估JavaScript语句
var bar = ‘bar‘; // if variable bar equals ‘bar‘, foobar is the result of // last executing statement: bar="foo-bar"; var foobar = eval(‘if(bar == "bar") {bar="foo-bar";} else {bar = "bar-foo";}‘); alert(foobar);// change the valuebar = ‘foo‘; // now our the last executed statement is: bar = "bar-foo"; // therefore the value of variable foobar has been changed // into ‘bar-foo‘ foobar = eval(‘if(bar == "bar") {bar="foo-bar";} else {bar = "bar-foo";}‘); alert(foobar);
JSON的格式
var objectLiteral = { name: "Objector.L", age: "24", special: "JavaScript", sayName: function() { return this.name; } };
JSON对象
var jsonFormat = { "summary": "Blogs", "blogrolls": [ { "title": "Explore JavaScript", "link": "http://example.com/" }, { "title": "Explore JavaScript", "link": "http://example.com/" } ] };
var jsonObject = eval("(" + jsonFormat + ")");
alert(eval("{}"); // return undefined alert(eval("({})");// return object[Object]
alert(eval(‘{foo:"bar"}‘)); // return "bar", incorrect
eval正确解析JSON
alert(eval(‘({"foo": "bar"})‘)); // return JSON object, correct
eval(‘(‘ + jsonString + ‘)‘);
标签:eva color log 参考 ajax net rip result 服务
原文地址:http://www.cnblogs.com/sunnywindycloudy/p/7382233.html