Skip to content

Instantly share code, notes, and snippets.

@donburks
Last active August 29, 2015 14:12
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 donburks/6e266289fa29735bcad2 to your computer and use it in GitHub Desktop.
Save donburks/6e266289fa29735bcad2 to your computer and use it in GitHub Desktop.
Non-Instance Safe JS
function Cat(colour, size) {
this.colour = colour;
this.size = size;
}
Cat.prototype.meow = function() {
console.log("Meow");
};
function Garfield() {
}
Garfield.prototype = new Cat('orange', 'fat');
var gf = new Garfield();
gf.meow(); //Meow, as expected.
Cat.prototype.swish = function() {
console.log("TAIL SWISH!");
};
gf.swish(); //TAIL SWISH, even though it wasn't part of the original inheritance.
@donburks
Copy link
Author

donburks commented Jan 8, 2015

@VengadoraVG: Thanks for the comment, however this particular Gist was used as part of a blog post to demonstrate precisely Elliot's technique. Please see: http://www.donburks.com/mixin-up-your-objects/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment