Skip to content

Instantly share code, notes, and snippets.

@moredip
Created January 9, 2012 03:37
Show Gist options
  • Save moredip/1580895 to your computer and use it in GitHub Desktop.
Save moredip/1580895 to your computer and use it in GitHub Desktop.
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