1
我有這樣的代碼在我的應用程序:觀察員:我應該使用傳遞給函數值,或者我可以用THIS.VALUE安全呢?
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
設置爲一個函數參數,但不是?
太棒了。謝謝。 – Merc