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的原因之一:)试试这个: