gpt4 book ai didi

javascript - 没有在 Javascript 中获得正确的登录

转载 作者:行者123 更新时间:2023-12-03 07:05:37 24 4
gpt4 key购买 nike

我只是在测试一些东西,因为我开始使用 VSCode,然后我意识到一些我认为是错误的。每当我只记录使用方法计算的内容时,它都会记录函数:方法名称。有什么建议吗?

例子:

class square {
constructor(width, height) {
this.width = width;
this.height = height;
}

get area() {
return this.calculateArea
}

calculateArea() {
this.width * this.height
}
}

const square1 = new square(5, 8);
console.error(square1.area);

这会记录 [函数:计算面积]。

最佳答案

您返回的是函数,而不是结果。

应该是return this.calculateArea()

关于javascript - 没有在 Javascript 中获得正确的登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64860376/

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