我正在尝试在函数内部克隆一个 json 对象,以访问函数外部的对象。但是当函数完成时,对象似乎仍然是未定义的。好像不是同一个变量?
var jsonUserObj;
$.getJSON("user.json", function(content){
jsonUserObj = $.parseJSON(JSON.stringify(content));
console.log(content);
console.log(jsonUserObj); //looks fine!
});
console.log(jsonUserObj); //undefined
在回调函数内部,它包含所有数据,但不会保留在其外部。如何使其在全球范围内可评估?