Last active
August 29, 2015 14:12
-
-
Save donburks/6e266289fa29735bcad2 to your computer and use it in GitHub Desktop.
Non-Instance Safe JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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/