为什么在将键值对推入 $scope 对象时重用它时会得到未定义的值?

Why do I get undefined value when I reuse it while pushing the key-value pairs into the $scope object?

我正在尝试将评论添加到 $scope.comments 数组。除初始键外,所有键值对都被推入 $scope.comments。其中必须缩短 capitaliseUsername(comment.owner).

$scope.comments.push({
  id: comment.id,
  text: comment.text,
  timestamp: comment.timestamp,
  owner: comment.owner,
  card: comment.card,
  initial: capitaliseUsername(comment.owner) //why is comment.owner value undefined here
}

但是从服务器返回的评论数组包含 comment.owner 值,因为所有者密钥工作正常。

查看评论返回的 JSON 数据的屏幕截图。

函数 capitaliseUsername(comment.owner) 必须需要 return 在注释数组中的 "initial" 中赋值的东西;

这里 comment.owner 可以,但是因为 capitaliseUsername(comment.owner) 没有 return 并且为此 "initial" 赋值未定义。