Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Created July 15, 2014 18:05
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 meeDamian/7f144956618d301356dc to your computer and use it in GitHub Desktop.
Save meeDamian/7f144956618d301356dc to your computer and use it in GitHub Desktop.
Random extend example
class Orange extends Fruit
constructor: ->
console.log 'Orange created'
peel: ->
console.log 'Oh god, that hurts'
orange = new Orange()
orange.peel()
var Orange, orange,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Orange = (function(_super) {
__extends(Orange, _super);
function Orange() {
console.log('Orange created');
}
Orange.prototype.peel = function() {
return console.log('Oh god, that hurts');
};
return Orange;
})(Fruit);
orange = new Orange();
orange.peel();
var util = require('util');
var Orange = function() {
console.log('Orange created');
};
util.inherits(Orange, Fruit);
Orange.prototype.peel = function() {
console.log('Oh god, that hurts');
};
var orange = new Orange();
orange.peel();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment