addyosmani / largescale-demo

Scalable JS architecture demo for #jqcon
138 stars 26 forks source link

Private variables vs instance properties #3

Open stevenut opened 12 years ago

stevenut commented 12 years ago

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
        }
    }    
});
addyosmani commented 12 years ago

@stevenut Hi! I didn't realize anyone was still using this repo for reference :) I would recommend checking out Backbone Aura - my more recent project based on some similar concepts as the largescale demo.