gpt4 book ai didi

javascript - 向对象参数添加函数

转载 作者:行者123 更新时间:2023-12-02 18:36:58 24 4
gpt4 key购买 nike

我有大约 50 个对象,例如:

object[0].one = something;
object[0].two = else;
object[0].options = whatever;

不知道如何描述它,但它们都有子参数。我试图添加一个额外的参数,我只会手动添加到我想要的参数,如下所示:

object[15].condition = function() { if (something) { then do something; } } ;
//and then later on in a function do
if (this.condition) {
this.condition;
}

但我无法让它工作=(这样的事情可能吗?非常感谢任何帮助。

最佳答案

if (this.condition) {
this.condition();
}

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

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