addyosmani / addyosmani/largescale-demo

Private variables vs instance properties

未關閉
#3 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
JavaScript
星號
137
分支
23
PR 合併指標
30 天內沒有已合併 PR

描述

Hi, this is more of a question than issue but can anyone explain why you might want to create errorNotice as a private variable in the first version of this module versus as a property on the instance in the second version? It seems in the first version you have to clean up the private variable whereas in the second version it will be removed when the instance is destroyed. Thanks!

```
// First version
app.core.define('#error', function(f){
var errorNotice;

return {
init: function(){
errorNotice = f.find('#alert')[0];
},

destroy: function(){
errorNotice = null;
}
}
});

// Second version
app.core.define('#error', function(f){
return {
init: function(){
this.errorNotice = f.find('#alert')[0];
},

destroy: function(){
// No longer need to null-out errorNotice
}
}
});
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。