gpt4 book ai didi

javascript - 从另一个函数向函数内部的对象添加值

转载 作者:行者123 更新时间:2023-11-30 14:58:04 27 4
gpt4 key购买 nike

我希望通过另一个对象中的方法更新 chaseObj 中的值。请指教,谢谢!

var s, searchUts;
var getValue = '';
var generateObject = function() {
var chaseObj = {
"timeFilters" : getValue
};
return chaseObj;
};

searchUts = s = {
createValue: function() {
var x = 10;
var y = 20;
getValue = x + y; //append this value to chaseObj inside the generateObject
},
postToBackEnd: function() {
var chaseObj = generateObj();
$.ajax({
url: localhost:8080/site/home,
data:JSON.stringify(chaseObj) //chaseObj is not updated with new value here

})
}

};

最佳答案

不清楚你想要什么,但这就是你想要的结果吗?

var s, searchUts;
var getValue = '';
var generateObject = function() {
var chaseObj = {
"timeFilters" : getValue
};
return chaseObj;
};

searchUts = s = {
createValue: function(obj) {
var x = 10;
var y = 20;
obj.timeFilters = x + y; //append this value to chaseObj inside the generateObject
},
postToBackEnd: function() {
var chaseObj = generateObject();
this.createValue(chaseObj);
console.log(JSON.stringify(chaseObj));
}
};

s.postToBackEnd();

关于javascript - 从另一个函数向函数内部的对象添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46945092/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com