Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Last active August 29, 2015 14:07
Show Gist options
  • Save AlexArchive/eece353cbd93e2c50b3c to your computer and use it in GitHub Desktop.
Save AlexArchive/eece353cbd93e2c50b3c to your computer and use it in GitHub Desktop.
/*
Instead of repeating cross-cutting concerns in every function, we
can use the "doWork" function as an abstraction.
*/
var work = function(){
console.log("working hard");
};
var doWork = function(func){
console.log("starting");
try {
func();
}
catch(ex){
console.log(ex);
}
console.log("ending");
};
doWork(work);
// Immediately invoked function expression or IFFE.
(function() {
var createFunc = function() {
return function () {
console.log("hello.");
}
}
var func = createFunc();
func();
})();
// Revealing module pattern.
var createWorker = function(){
// Encapsulate code inside of a function/module.
var job1 = function() {
console.log("job1");
};
var job2 = function() {
console.log("job2");
};
return {
job1: job1,
job2: job2
}
};
var worker = createWorker();
worker.job1();
worker.job2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment