我在我的代码中有一个模块,我无法更改对象的属性的值。我有代码更详细的解释,见下图:无法更改对象的属性值 - JavaScript
var network = (function(){ // Created a closure.
var ajax = {
response: 0, // I set the initial value of response to 0
parse: function(x){
var y = JSON.parse(x);
ajax.response = y; // This is where things don't seem to work. Value of response is still 0.
}
// Some other code.
} // End of ajax object.
return { // I return an Object .
invoke: function(x){ ajax.parse(x); },
reply: ajax.response
}
})();
network.invoke(valid_argument); // I invoke the function and pass a valid json string received from a server via ajax.
console.log(network.reply); // I get 0, which is the initial value. Why?
由于在这个问题上感觉怪怪的代码中提到,任何帮助表示赞赏。
函数中没有_response_可用。它位于ajax对象内 – brk
ajax中的“a”代表*异步*? – adeneo
@brk哎呀!这应该是答复,我现在纠正它。你可以看看现在吗? – Teja