gpt4 book ai didi

javascript 在 return 中返回项目

转载 作者:行者123 更新时间:2023-12-03 10:17:52 27 4
gpt4 key购买 nike

我想像这样构建我的应用程序:

APP.open = (function ($) {
return {
people: function() {
return {

gender: function() {},

age: function() {}
}
}
};
}(jQuery));

我可以获得APP.open.people(),但是当我这样做时:APP.open.people.gender();我得到undefined.

最佳答案

您可以执行以下操作来实现您的要求:请注意围绕 people 分配的匿名函数。

APP.open = (function ($) {
return {
people: (function() {
return {

gender: function() {},

age: function() {}
}
})()
};
}(jQuery));

关于javascript 在 return 中返回项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29779117/

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