Skip to content

Instantly share code, notes, and snippets.

@jyotiarora2610
Created August 27, 2019 14:35
Show Gist options
  • Save jyotiarora2610/c62031496810037006c87068f795eff2 to your computer and use it in GitHub Desktop.
Save jyotiarora2610/c62031496810037006c87068f795eff2 to your computer and use it in GitHub Desktop.
// Wrong way, bcoz variables are exposed.
// var foo = {
// o: {bar: 'fghj'},
// test() {
// console.log('hello');
// }
// }
// foo.test();
// console.log(foo.o);
var foo = (function() {
var o = {foo: 'bar'};
return {
bar: function() {
console.log(o.foo);
}
}
})();
foo.bar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment