传递给函数的参数在等待后消失

时间:2019-06-28 03:18:54

标签: javascript

在下面的代码中,在等待之后,user_message和bot参数消失了,我不明白为什么。

const process_user_message = async ({user_message, bot}) => {
  console.log('before await…')
  console.log(user_message)                     // logs lovely big object
  console.log(typeof user_message)              // logs 'object'
  df_result = await df_query({
    query: user_message.text,
    session_id: user_message.channel,
    bot: bot
  })
  console.log('after await…')
  console.log(user_message)                     // logs nothing :(
  console.log(typeof user_message)              // logs nothing :(

  bus.emit('message from dialogflow', {
    bot,
    df_result,
    user_message
  })
}

1 个答案:

答案 0 :(得分:0)

看起来从未定义过df_result。

const process_user_message = async ({user_message, bot}) => {
  const df_result = await df_query({
    query: user_message.text,
    session_id: user_message.channel,
    bot: bot
  });
  console.log(typeof user_message)
  ...
}