Skip to content

Instantly share code, notes, and snippets.

@jagoda
Created February 23, 2014 19:47
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 jagoda/9176336 to your computer and use it in GitHub Desktop.
Save jagoda/9176336 to your computer and use it in GitHub Desktop.
factory pattern
function rectangle (length, width) {
var rectangle = Object.create(null);
rectangle.area = function () {
return length * width;
};
return rectangle;
}
function square (side) {
var rectangle = rectangle(side, side);
var square = Object.create(rectangle);
return square;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment