-3

这里我有一个功能nArray。此函数必须返回 bigArray(JSON 对象),但函数不返回 bigArray...

http://jsfiddle.net/u58k6/29/

function nArray() {

//CODE IS HERE

        return bigArray;
}
console.log(nArray);
$('pre').html(JSON.stringify(nArray, null, 4));

问题是什么?

4

2 回答 2

1

nArray是一个函数,所以你需要通过添加括号来执行它:

console.log(nArray());
$('pre').html(JSON.stringify(nArray(), null, 4));

目前,您只是传递对该函数的引用。

于 2013-08-01T12:09:49.490 回答
1

你实际上并没有调用你的函数。做这个:

console.log(nArray());
//                ^^-----------note the parentheses
$('pre').html(JSON.stringify(nArray(), null, 4));
//                                 ^^-----------and here

关于您的小提琴,我看不到其中的任何<pre>元素,因此尝试设置.html()a的最后一行代码$('pre')不会做任何事情。

于 2013-08-01T12:09:51.237 回答