Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.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 如果不使用模块显示模式,我是否可以访问;这";在匿名函数中?_Javascript_Angularjs - Fatal编程技术网

Javascript 如果不使用模块显示模式,我是否可以访问;这";在匿名函数中?

Javascript 如果不使用模块显示模式,我是否可以访问;这";在匿名函数中?,javascript,angularjs,Javascript,Angularjs,如果我有以下代码。使用self变量是我访问函数内部this的唯一方法,还是我可以访问函数内部this的另一种方法 app.controller('ChildCtrl', function($scope, _o) { var self=this; this.option = {}; this.option.abc = 25; $q.all([_o.getUserProfiles(), _u.getConfigs() ]) .t

如果我有以下代码。使用
self
变量是我访问函数内部
this
的唯一方法,还是我可以访问函数内部
this
的另一种方法

app.controller('ChildCtrl', function($scope, _o) {

  var self=this;
  this.option = {};
  this.option.abc = 25;

  $q.all([_o.getUserProfiles(),
          _u.getConfigs()
        ])
        .then(function (results) {
            ???.option.userProfiles = results[0].userProfiles;
        });

你可以使用bind。也许这会让你更舒服

app.controller('ChildCtrl', function($scope, _o) {

  this.option = {};
  this.option.abc = 25;

  $q.all([_o.getUserProfiles(),
          _u.getConfigs()
        ])
        .then(function (results) {
            this.option.userProfiles = results[0].userProfiles;
        }.bind(this));
有关bind的更多信息,您可以在此处阅读:


您可以使用bind。也许这会让你更舒服

app.controller('ChildCtrl', function($scope, _o) {

  this.option = {};
  this.option.abc = 25;

  $q.all([_o.getUserProfiles(),
          _u.getConfigs()
        ])
        .then(function (results) {
            this.option.userProfiles = results[0].userProfiles;
        }.bind(this));
有关bind的更多信息,您可以在此处阅读:


我提出了一个类似的问题:我是否也可以在那里使用.bind作为foo函数?这是我使用coffeescript的原因之一:)试试这个:我提出了一个类似的问题:我是否也可以在那里使用.bind作为foo函数?这是我使用coffeescript的原因之一:)试试这个: