Created
January 9, 2012 03:37
-
-
Save moredip/1580895 to your computer and use it in GitHub Desktop.
Class-less JS post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createDuck( name ){ | |
var duck = { | |
fullName: function(){ name + " duck"; } | |
}; | |
return duck; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createLogger( category ){ | |
// some implementation here | |
}; | |
function createDuck( name, logger ){ | |
return { | |
speak: function(){ | |
logger( name + ' was asked to speak' ); | |
return 'quack'; | |
} | |
}; | |
}; | |
(function boot(){ | |
var duckLogger = createLogger('duck'); | |
function curriedCreateDuck(name){ | |
return createDuck( name, duckLogger ); | |
} | |
globals.createDuck = curriedCreateDuck; | |
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var shouter = { | |
shout: function(){ return this.speak().toUpperCase(); } | |
}; | |
function createShoutyDuck( name ){ | |
return _.extend( createDuck(name), shouter ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment