Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Created November 22, 2014 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessioalex/ab84c2daef8ae49ad49c to your computer and use it in GitHub Desktop.
Save alessioalex/ab84c2daef8ae49ad49c to your computer and use it in GitHub Desktop.
configurable-logger-example.js
// TODO: given the log function previously created, create a prefixed logger
// function that takes a {String} as an argument.
// That string should be used as the first argument to the regular `log` function.
var log = function log() {
var args = Array.prototype.slice.call(arguments);
console.log(args.join(' '));
};
// log('hello', 'world', '!');
// -> Hello world !
function createLogger(prefix) {
return function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(prefix);
// second argument === Array
log.apply(null, args);
};
}
// Example:
var logger = createLogger('MyApp ::');
logger('hello', 'world', '!');
// -> MyApp :: Hello world !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment