从对象字面量模式返回值
大家好,想知道是否有人可以帮助我,我正在使用对象文字模式来组织我的代码(我是这个模式的新手)。我试图从函数返回变量的值,但它不断返回整个函数 - 有人可以告诉我我做错了什么吗这里是我的代码片段 -
'teamStatusTableHeight': function() {
var theHeight = $(".teamStatusTable").height() - 130;
return theHeight;
},
'numOfTeamMembers': function() {
var numTeams = $(".teamStatusTable tr").length;
return numTeams
} ,
'scrollDistance': function() {
var scroll = teamStatus.teamStatusTableHeight / teamStatus.numOfTeamMembers + 30;
return scroll;
}
任何帮助将不胜感激。
Hi guys wondering if someone can help me, I am using the object literal pattern to organise my code (I'm new to this pattern). I am trying to return the value of a variable from a function but it keeps returning me the whole function - could someone tell me what I am doing wrong here is a snippet from my code -
'teamStatusTableHeight': function() {
var theHeight = $(".teamStatusTable").height() - 130;
return theHeight;
},
'numOfTeamMembers': function() {
var numTeams = $(".teamStatusTable tr").length;
return numTeams
} ,
'scrollDistance': function() {
var scroll = teamStatus.teamStatusTableHeight / teamStatus.numOfTeamMembers + 30;
return scroll;
}
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要调用这些函数,如下所示:
注意添加的
()
,以便您使用的是函数的结果,而不是函数本身他们自己。You need to call those functions, like this:
Note the added
()
so you're using the result of the functions, not the functions themselves.这对我来说看起来不错。也许您实际上并没有调用该函数?
你把括号去掉了吗?他们需要实际执行该功能。否则它们只是提供对函数对象本身的访问。
That looks fine to me. Perhaps you are not actually calling the function?
Did you leave off the parentheses? They are required to actually execute the function. Otherwise they simply provide access to the function object itself.