javascript - Issues with callback function -


this question has answer here:

i have simple question has been bouncing on head how handle this. i've been using api requires callback function capture values, , i'm having issues in returning output of function other functions i'm using on project.

for example:

function a() { var callback = function(e) {   var id = e.data.responsedata.id; }; api.getid(callback);     } 

if try call variable id, give me undefined i'm assuming id value not being passed available globally.

on other side if run this:

function a() {     var callback = function(e) {       var id = e.data.responsedata.id;       console.log(id);     };     api.getid(callback);         } 

it return me on console correctly value of id.

any ideas on i'm missing here?

thanks once again.

rafa

you need return variable "id" in function:

function a() { var callback = function(e) {   var id = e.data.responsedata.id;   return id; }; api.getid(callback);     } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -