PhoneGap中文网
标题:
关于this和that的模糊概念
[打印本页]
作者:
jiangxujing11
时间:
2015-12-15 14:03
标题:
关于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?求指教
作者:
你懂的
时间:
2015-12-15 15:11
that 表示临时保存this指针,不然方法里面套方法,就不知道 this是谁了
作者:
jiangxujing11
时间:
2015-12-16 10:55
有用,谢啦
欢迎光临 PhoneGap中文网 (http://bbs.phonegap100.com/)
Powered by Discuz! X3.2