求解决,这是在类里还是在函数里,如何能调用其中的变量

求解决,这是在类里还是在函数里,怎么能调用其中的变量?
一段程序



HTMLActuator.prototype.updateBestScore = function (bestScore) {
  this.bestContainer.textContent = bestScore;
  window.n=bestScore
   
  alert(window.n);  //这里能提示数值

};

  var shareTitle ="你的成绩是"+ window.n +"!";

最后window.n 则返回的是 undefined  为什么呢?


------解决方案--------------------
HTMLActuator.prototype.updateBestScore 是异步调用执行的,要在updateBestScore中改shareTitle的值


HTMLActuator.prototype.updateBestScore = function (bestScore) {
  this.bestContainer.textContent = bestScore;
  shareTitle ="你的成绩是"+ bestScore +"!";
};
var shareTitle;