我想在函数外访问 const newdata function updateFields(response) { $("#FIELDSET").removeProp('disabled'); const parser = new DOMParser(); const xmlDoc = parser.parseFromString(response, "text/xml"); const data = xmlDoc.getElementsByTagName("responses")[0].innerHTML; const rdata = data.split('//')[0] const payload = data.split(':1:1,') .map(x => x.split('=')) .reduce((obj, x) => { obj[x[0].replace(/\./g, '_')] = x[1]; return obj; }, {}) const newdat="string"; CO_CODE=payload.CO_CODE.split(':1:1')[0] const {AMOUNT, INT_RATE, TERM, FREQUENCY, REP_START_DATE, CUSTOMER_ID, INSTALMENT} = payload; }
3 回答

慕勒3428872
TA贡献1848条经验 获得超6个赞
如果newdat不是特定于——或特别依赖于——你的updateFields方法,你可以在updateFields范围之外维护它;每当updateFields被调用时更新它。
let newdat = '';
function updateFields() {
// ...
newdat = "string";
// ...
}
function someOtherFunction() {
console.log( 'newdat =' + newdat ); // would log the current value of `newdat` when called
}
let newdat = '';
function updateFields() {
newdat = "string";
}
function someOtherFunction() {
console.log('newdat = ' + newdat); // would log the current value of `newdat` when called
}
updateFields();
someOtherFunction();
添加回答
举报
0/150
提交
取消