无限循环的对象问题中的JavaScript函数
试图在我的对象中声明功能,但是在我的代码中,它在我的代码中说了无限循环。我试图将其声明为正常函数,但我的IDE只希望它像下面一样声明,但是当我进行编译时它说无限循环。
let movie = {
title: "Forrest Gump",
director: "Robert Zemeckis",
composer: "Alan Silvestri",
budget: 55000000,
boxOffice: 677900000,
awards: [],
totalRevenue: function () {
let x = this.movie.boxOffice - this.movie.budget;
return x;
},
};
Was trying to declare a function in my object but inside my code it is saying infinite loop within my code. I tried to declare it as a normal function but my IDE only wants it declared like it is below but yet it says infinite loop when I compile it.
let movie = {
title: "Forrest Gump",
director: "Robert Zemeckis",
composer: "Alan Silvestri",
budget: 55000000,
boxOffice: 677900000,
awards: [],
totalRevenue: function () {
let x = this.movie.boxOffice - this.movie.budget;
return x;
},
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
delete
电影
在您的函数中:您的代码是错误,因为它试图在
对象中找到一个名为“电影”的对象。如果您这样做对象,您的功能将起作用:
Delete
movie
in your function:Your code is error because it's trying to find an object called "movie" in
this
object which you don't have. Your function will work if you make your object like this:在您的代码中,属于电影对象,因此从您的功能中删除电影,您可以直接调用
boxoffice
和预算
,因为它属于<代码>此,还有一件事,您的代码不会在无限的循环中进行,而不是无法找到
Movie
Inside 此In your code
this
belong to movie object, so remove movie from your function you can directly invokeboxoffice
andbudget
because it is belong to thethis
And one more thing your code is not going in infinite loop rather than it is unable to find
movie
insidethis