Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
var app = (function(d, w){
var myPrivateVariable = "My private content";
var __private = {
cache : function(){
this.link = d.querySelector('.link-item');
}
bind : function(){
this.link.addEventListener('click', this.handleClick, false);
},
handleClick: function(){
console.log(myPrivateVariable);
}
};
var app = {
init: function(){
console.log(myPrivateVariable);
__private.cache();
__private.bind();
}
};
return app;
})(window, document);
app.init(); //init the app
console.log(myPrivateVariable); // undefined
@3emad

Thanks for sharing this, its awesome!

@albiere

I really like this approach!
However, I'd rather improve the public API in this case. Why are the functions "cache" and "bind" public?

What do you think?

@guilhermepontes

@albiere makes sense. Updated! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.