这是jsfiddle
完整代码:
function foo1(){
return {msg: "hello1"};
}
function foo2(){
return
{msg: "hello2"};
}
// output = "foo1 = {"msg":"hello1"}"
console.log('foo1 = ' , JSON.stringify(foo1()));
//output = " foo2 = undefined "
console.log('foo2 = ' , JSON.stringify(foo2()));
两者的区别在于,在 foo2 中,{msg: 'hello'}
是在自己的新行中。我期望解析器忽略空格?