Skip to content

Instantly share code, notes, and snippets.

@or9
Last active August 29, 2015 14:18
Show Gist options
  • Save or9/3af4d2ee109862878241 to your computer and use it in GitHub Desktop.
Save or9/3af4d2ee109862878241 to your computer and use it in GitHub Desktop.
Revealing module app thing
var app = (function init(doc, undefined) {
// do stuff
return Object.defineProperties({}, {
"hi": { value: hi },
"bye": { value: bye }
});
function hi() {
// hi
}
function bye() {
// bye
}
})(document);
undefined = true;
var app = (function init(doc, undefined) {
var thing = 0;
return {
hi: hi,
bye: bye,
something: thing, // copy by value
get thing() {
return thing;
}
};
function hi() {
thing += 1;
}
function bye() {
thing += 2;
}
})(document);
app.something; // 0
app.thing; // 0
app.hi();
app.something; // 0
app.thing; // 1
app.bye();
app.something; // 0
app.thing; // 3
var app = (function init(doc, undefined) {
// do stuff
return {
hi: hi,
bye: bye
};
function hi() {
// hi
}
function bye() {
// bye
}
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment