观察者:我应该使用传递给函数的值,还是可以安全地使用 this.value 代替?
Observers: should I use values passed to the function, or can I use this.value safely instead?
我的应用程序中有这样的代码:
observers: [
'_dataGenericObserver(userData.generic)',
],
// If this.userData.generic.id is set, then the register tab is
// NOT visible. In this case, the selected tab mustn't be "register"...
_dataGenericObserver: function(){
if (this.userData.generic.id){
this.selected = 'login';
} else {
if (this.defaultRegister) {
this.selected = 'register';
} else {
this.selected = 'login';
}
}
},
这里安全吗?或者我应该 总是 这样做:
observers: [
'_dataGenericObserver(userData.generic)',
],
// If this.userData.generic.id is set, then the register tab is
// NOT visible. In this case, the selected tab mustn't be "register"...
_dataGenericObserver: function(generic){
if (generic.id){
this.selected = 'login';
} else {
if (this.defaultRegister) {
this.selected = 'register';
} else {
this.selected = 'login';
}
}
},
……?
我注意到在某些情况下,在应用程序的其他部分,如果我在 _someFunc(value.subvalue)
上有一个观察者,然后在 _someFunc: function( subValue)
上设置了函数 subValue
,而 this.value.subValue
不是。但是,我无法复制它 - 抱歉。
问题:
- 是否始终建议使用传递给函数的值,而不是
this.*
?
- 什么时候可能会发生
subValue
被设置为函数参数,但不是 this.value.subValue
?
我的应用程序中有这样的代码:
observers: [
'_dataGenericObserver(userData.generic)',
],
// If this.userData.generic.id is set, then the register tab is
// NOT visible. In this case, the selected tab mustn't be "register"...
_dataGenericObserver: function(){
if (this.userData.generic.id){
this.selected = 'login';
} else {
if (this.defaultRegister) {
this.selected = 'register';
} else {
this.selected = 'login';
}
}
},
这里安全吗?或者我应该 总是 这样做:
observers: [
'_dataGenericObserver(userData.generic)',
],
// If this.userData.generic.id is set, then the register tab is
// NOT visible. In this case, the selected tab mustn't be "register"...
_dataGenericObserver: function(generic){
if (generic.id){
this.selected = 'login';
} else {
if (this.defaultRegister) {
this.selected = 'register';
} else {
this.selected = 'login';
}
}
},
……?
我注意到在某些情况下,在应用程序的其他部分,如果我在 _someFunc(value.subvalue)
上有一个观察者,然后在 _someFunc: function( subValue)
上设置了函数 subValue
,而 this.value.subValue
不是。但是,我无法复制它 - 抱歉。
问题:
- 是否始终建议使用传递给函数的值,而不是
this.*
? - 什么时候可能会发生
subValue
被设置为函数参数,但不是this.value.subValue
?