Search code examples
javascriptreturn-valueobject-literal

Return value from object literal patern


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.


Solution

  • 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.