Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript OOP可视范围_Javascript_Ajax_Oop - Fatal编程技术网

JavaScript OOP可视范围

JavaScript OOP可视范围,javascript,ajax,oop,Javascript,Ajax,Oop,我的代码如下所示: function A() { this.AFunction = function() { var b = new B(); b.BFunction(); } } function B() { this.BFunction = function() { // some code $.ajax({ url: url success: BSuccess,

我的代码如下所示:

function A() {
    this.AFunction = function() {
        var b = new B();
        b.BFunction();
    }
}

function B() {
    this.BFunction = function() {
         // some code
         $.ajax({ url: url
             success: BSuccess,
             // and so on
         })
    }

    this.BSuccess = function() {
         // some code
         this.anotherBFunc();
    }

    this.anotherBFunc = function() {
         // some code
    }
}

a = new A();
a.AFunction();

它在调用另一个bFunc时失败。有人能帮我理解为什么会这样吗?

为了维护您可以使用的范围

或者使用现代浏览器


一些阅读:使用
this.bsucces.bind(this)
:你说的“现代”是指“任何人实际使用的浏览器”:)恐怕人们仍然使用IE8,而且它并不现代。据估计,全球互联网的10%左右,这就有一点。。。全球!==公司的用户群。好吧,你们赢了:InternetExplorer8有着美好的未来,值得花钱无限期支持。成本效益分析非常支持不仅只针对浏览器,而且我们都应该仅凭该软件的力量购买微软的股票P
success: $.proxy(this.BSuccess,this),
success: this.BSuccess.bind(this),