Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View module.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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

Thanks for sharing this, its awesome!

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?

@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.