Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save gregtatum/d551256d8e1bbc0ed639 to your computer and use it in GitHub Desktop.

Select an option

Save gregtatum/d551256d8e1bbc0ed639 to your computer and use it in GitHub Desktop.
State and config in a function
function logger( state, msg ) {
state.count++
console.log( state.count, this.msg )
}
var log = () => logger( {count:0}, "Calling from an arrow function" )
log()
log()
log()
function logger() {
this.count++
console.log( this.count, this.msg )
}
var log = logger.bind({
count: 0,
msg: "Logging from a bound function"
})
log()
log()
log()
function createLogger( msg ) {
var count = 0
return function() {
count++
console.log( count, msg )
}
}
var log = createLogger( "Trapping variables in a closure" )
log()
log()
log()
function Logger( msg ) {
this.msg = msg
this.count = 0
}
Logger.prototype.log = function() {
this.count++
console.log( this.count, this.msg )
}
var logger = new Logger("A typical Object Oriented logger")
logger.log()
logger.log()
logger.log()
function logger( state, msg ) {
state.count++
console.log( state.count, this.msg )
}
var log = _.partial( logger, {count:0}, "Calling from a partially applied function" )
log()
log()
log()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment