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 摘要。