关于this和that的模糊概念
app.config(function(providerServices01Provider){providerServices01Provider.name = "zhangsan";
})
app.provider("providerServices01",function(){
this.name = "";
this.$get = function(){
var that = this;
var _name = "";
var service = {};
service.setName = function(name){
_name = name;
}
service.getName = function(){
return _name;
}
service.getConfigName = function(){
return that.name+"123456";
}
return service;
}
})
这里为什么要用var that = this,不然返回的this.name就是未定义,必须用that.name?求指教
that 表示临时保存this指针,不然方法里面套方法,就不知道 this是谁了 有用,谢啦
页:
[1]