Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save gregtatum/37ec564a5a7ee159719c to your computer and use it in GitHub Desktop.
Module Pattern - Killing this
var internals = {
revEngine : function rev( state, engine ) {
state.timesRevved++
switch( engine ) {
case "v8":
console.log("vrooooooooom!")
break
case "v6":
console.log("vroooom")
break
default:
console.log("vroom")
}
},
}
module.exports = function createCar( engine ) {
var state = {
timesRevved: 0
}
return {
rev : _.partial( revEngine, state, engine ),
timesRevved : () => state.timesRevved
}
}
var CreateCar = require('./car')
var normalCar = CreateCar( "v6" )
console.log( normalCar.timesRevved() )
normalCar.rev()
console.log( normalCar.timesRevved() )
var fastCar = car( "v8" )
fastCar.rev()
fastCar.rev()
console.log( fastCar.timesRevved() )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment