Paul,
Function bind is used to bind both the thisArg (i.e. the value of `this` inside a function), and its positional parameters (partial application). The way you've used bind() in your example, it will bind the value of `data` to `this` inside compileTemplate's, but compileTemplate expects `data` as its second parameter.
Since compileTemplate appears not to need a `thisArg`, one possible way you could refactor is:
// Note parameter order
function compileTemplate(data, value) {
// code as before
}
function mergeTemplates(data) {
// Since compileTemplate doesn't need a thisArg, can use undefined (or anything, really)
return when.map(data.bodies, compileTemplate.bind(undefined, data))
.then(...);
}
That will pass as the mapper function a version of compileTemplate that has its first formal parameter fixed to `data`.