gpt4 book ai didi

javascript - 我如何编写一个函数来设置父对象中变量的值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:01:11 24 4
gpt4 key购买 nike

我创建了以下对象:

app.state = {
message: {
clear: function() {
message.error = null;
message.text = null;
},
alert: function(text) {
message.error = true;
message.text = text;
},
set: function(text) {
message.error = null;
message.text = text;
},
error: null,
text: null,
}
}

但是,当我调用 app.state.message.set('abc') 时,我收到一条错误消息,指出消息未定义。有人可以告诉我如何进行这项工作吗?有什么方法可以设置父对象吗?

最佳答案

app.state = {
message: {
clear: function() {
this.error = null;
this.text = null;
},
alert: function(text) {
this.error = true;
this.text = text;
},
set: function(text) {
this.error = null;
this.text = text;
},
error: null,
text: null,
}
}

关于javascript - 我如何编写一个函数来设置父对象中变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24146769/

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