Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Created November 9, 2014 19:46
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 aaronj1335/869a4f835b832ca7a41c to your computer and use it in GitHub Desktop.
Save aaronj1335/869a4f835b832ca7a41c to your computer and use it in GitHub Desktop.
function Button() {}
Button.prototype = {
color: 'blue',
border: '1px solid black'
};
// use classical inheritance or something like functional mixins to replicate
// the cascading nature of stylessheets
function ButtonActive() {}
ButtonActive.prototype = Object.create(Button.prototype);
ButtonActive.prototype.color = 'red';
// now we may save some memory since `border` is only defined on
// Button.prototype
//
// also multiple react component instances can share `buttonStyle` and
// `buttonActiveStyle`, we don't need to instantiate a new style object every
// time.
var buttonStyle = new Button();
var buttonActiveStyle = new ButtonActive();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment