Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created August 12, 2014 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotaroito/214c0c9cfeb247d96c9c to your computer and use it in GitHub Desktop.
Save kotaroito/214c0c9cfeb247d96c9c to your computer and use it in GitHub Desktop.
var abstractBallFactory = (function() {
var types = {};
return {
getBall: function(type, customizations) {
var constractor = types[type];
return ( constractor ? new constractor(customizations) : null );
},
registerBall: function(type, constractor) {
types[type] = constractor;
return abstractBallFactory;
}
};
})();
var Ball = function (customizations) {
this.radius = customizations.radius;
};
Ball.prototype = {
diameter: function() { return this.radius * 2; }
};
var SoccerBall = Ball;
SoccerBall.prototype = Ball.prototype;
(function() {
abstractBallFactory.registerBall("Brazuca", SoccerBall);
var brazuca = abstractBallFactory.getBall("Brazuca", {radius: 4.3});
console.log(brazuca.diameter());
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment