I have a function that connects to a API. That function returns a Promise. I can't figure out why Promise.resolve returns null when I'm resolving with a constant containing the this context.
const connect = () => {
return new Promise((resolve, reject) => {
Gitana.connect(config, function(err) {
const platform = this;
if (err) {
return reject(err);
}
console.log(platform) // Object that I want
resolve(platform)
});
});
}
connect()
.then(platform => {
console.log(platform) // null
})
I don't know if it is any help but I know there is a method on the resolve object (platform) called datastore. If I resolve that method, ie resolve(platform.datastore) I get the method, instead of null
I have tried to resolve static values, resolve(25) or resolve('hello') and that works fine.
How do I return/resolve the object?