Skip to content

Instantly share code, notes, and snippets.

@jonathanmarvens
Created December 9, 2013 04: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 jonathanmarvens/7867291 to your computer and use it in GitHub Desktop.
Save jonathanmarvens/7867291 to your computer and use it in GitHub Desktop.
(function () {
function Animal() {}
Object.defineProperties(Animal.prototype, {
noise: {
configurable: false,
enumerable: false,
value: null,
writable: false
}
});
Animal.prototype.makeNoise = function () {
throw new Error('You must override this method.');
};
function Dog() {
Animal.call(this);
}
Dog.prototype = Object.create(Animal.prototype);
Object.defineProperties(Dog.prototype, {
noise: {
configurable: false,
enumerable: false,
value: 'woof',
writable: false
}
});
Dog.prototype.constructor = Dog;
Dog.prototype.makeNoise = function () {
console.log(this.noise + '!');
};
var snoopy = new Dog();
if (snoopy instanceof Animal) {
console.log('snoopy is an instance of Animal.');
}
if (snoopy instanceof Dog) {
console.log('snoopy is an instance of Dog.');
}
snoopy.makeNoise();
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment