Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Class-less JS post
function createDuck( name ){
var duck = {
fullName: function(){ name + " duck"; }
};
return duck;
};
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;
}());
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
You can’t perform that action at this time.