gpt4 book ai didi

javascript - 返回对象 - javaScript

转载 作者:行者123 更新时间:2023-11-29 18:16:22 26 4
gpt4 key购买 nike

“foo”下面的函数不起作用。我想要一种方法来获得如下所示的输出,围绕“foo”中显示的原理工作。

function foo() {
var i;

i = "hello world";
i.a = "hello kitten";
i.b = "hello... Is there anybody out there?"

return i; // This doesn't work
}

这就是我想要的:

    alert(foo()); // "hello world"
var bar = foo();
alert(bar.a); // "hello kitten"
alert(bar.b); // "hello... Is there anybody out there?"

谢谢。

最佳答案

使用字符串对象而不是字符串值。

i = new String("hello world");

关于javascript - 返回对象 - javaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22963240/

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