I am trying to pass a string of json to this callback using .bind()
let ended = (endtype: typeof EndType.type, d: string)=>{
console.log(endtype.uri); // "/api/job"
console.log(d); // "" but not undefined
// process json
}
the params for it are ‘endtype’ and ‘d’, which are an object and a long string of json respectively
endtype:{
uri: "/api/whatever",
type: {} as response // blank instance of an interface to be passed to json parser
}
let recieve = (endtype: typeof EndType.type, response: IncomingMessage) => {
// code
response.on('end', ended.bind(null, endtype, d));
// more code
}
The endtype var comes through and data never does, regardless of if I rearrange the order of the function’s params
Have tried multiple different ways of running the bind function
.bind(null, endtype, d)
.bind(this, endtype, d)
.bind(null, endtype).bind(null,d)
I have tried wrapping the ‘d’ variable in an object and passing that to the bind function, which also doesn’t work.
.bind(null, endtype, {d})
I have verified that the ‘d’ variable does in fact have json in it when it is being referenced.
response.on('end', ()=>{console.log(d)}) // {"bunchajson":
I am really not sure what to do here, is what I am trying to do possible with bind()? This is my first attempt at functional programming so please be kind ( :