How can I use this
inside a callback? Using callback, I got undefined on this.callback() (this is undefined):
constructor(collection, journey, callback, environment=null) {
this.collection = collection;
this.journey = journey;
this.callback = callback;
console.log(this.callback)
this.environment = environment;
}
run() {
newman.run({
collection: this.collection,
environment: this.environment,
insecure: true
}, this.internalCallback).on('console', function (err, args) {
console.log(args.messages.join(' '));
})
}
internalCallback(error, summary) {
if(error || summary.error) throw (error || summary.error)
console.log(this)
this.callback(this.journey, summary) // here throws an error because this is undefined
}