如何在javascript中获取内部函数中的“this”外部函数

时间:2015-12-24 10:21:36

标签: javascript function oop

有人可以帮忙吗?当UpdateDataSuccessCallback运行时,'this.localData'总是未定义的,我想我没有得到RebateDataClass的this.localData,但是我怎么能在UpdateDataSuccessCallback中得到它?非常感谢

function RebateDataClass(d) {

    this.localData;
    var getdate = d;
    this.Init = function init() {
      getdata('get', "../tools/AgentRebateReportHandler.ashx?action=GetIndexData&dateType=" + getdate + "&r=" + Math.random, '', 'json', InitDataSuccessCallback, true);
    }

    function InitDataSuccessCallback(e) {
      this.localData = e.data;
      IndexPage.InitPage(getdate, e.data);
    }

    this.UpdateDataByDate = function UpdateData() {
      getdata('get', "../tools/AgentRebateReportHandler.ashx?action=GetIndexData&dateType=" + getdate + "&r=" + Math.random, '', 'json', UpdateDataSuccessCallback, true);
    }

    function UpdateDataSuccessCallback(e) {
      if (e.state == "ok") {
        IndexPage.UpdatePage(getdate, this.localData, e.data);
        //the this.localData is undefined
        this.localData = e.data;
      } else {

      }
    }

0 个答案:

没有答案