Sunday 8 January 2017

can you return a value of a promise.then()?

I'm using knex to retrieve data from my db.since knex is promised based it works likefunction getSomething(){ knex('table').then((rows) => { console.log(rows); }) } in my top level function, I'm pretty much calling the function above, but I need the value of the data.actualFunction(){ test = new class(); var result = test.getSomething(); console.log(result) // always undefined; } I have tried using 'return rows;' in the getSomething function, but it still returns undefined.I think i saw an exmple of async/await that would work, but even though I'm using babel my console error showed (await is a reserved word).What is another method of getting the return of my knex function into the actualFunction()?

Submitted January 09, 2017 at 05:08AM by paOol

No comments:

Post a Comment