Passing callback as parameter to another function JavaScript