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;
ret开发者_JS百科urn 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.
You need to call those functions, like this:
var scroll = teamStatus.teamStatusTableHeight() / teamStatus.numOfTeamMembers() + 30;
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?
// get the function
MyObj.teamStatusTableHeight
// run the function
MyObj.teamStatusTableHeight()
Did you leave off the parentheses? They are required to actually execute the function. Otherwise they simply provide access to the function object itself.
精彩评论