如何在javascript中调用函数内部的函数调用

时间:2017-04-27 06:28:43

标签: javascript facebook-graph-api

function getSenderName(senderId) {
      var __name;
      // Get user's first name from the User Profile API
      // and include it in the greeting
      request({
        url: "https://graph.facebook.com/v2.6/" + senderId,
        qs: {
          access_token: process.env.PAGE_ACCESS_TOKEN,
          fields: "first_name"
        },
        method: "GET"
      }, function(error, response, body) {
        if (error) {
          console.log("Error getting user's name: " +  error);
        } else {
          var bodyObj = JSON.parse(body);
          __name = bodyObj.first_name;
          console.log("1.SenderId : " + senderId + " Name : " + __name);
        }
      });
      console.log("2.SenderId : " + senderId + " Name : " + __name);
      return __name;
    }

上面的代码我得到了

1.SenderId : 1234 Name : Vinay
2.SenderId : 1234 Name : Undefined

任何人都可以帮助我如何访问这种嵌套函数内的变量

1 个答案:

答案 0 :(得分:1)

只是为了让你知道,


cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_GTK=ON -D WITH_V4L=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -DWITH_QT=OFF -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" ..

回调可以完成相同的工作..